Unix Technical Forum

Stored Procedure only works in when app uses trusted security

This is a discussion on Stored Procedure only works in when app uses trusted security within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I have a .NET application that connects to a SQL 2000 database using trusted security. It eventually calls ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:19 PM
ZRexRider
 
Posts: n/a
Default Stored Procedure only works in when app uses trusted security

Hi,

I have a .NET application that connects to a SQL 2000 database using
trusted security. It eventually calls a stored procedure that receives
3 parameters - nothing special.

If I simply change the connection string to use a valid Userid and
Password it still connects to the DB w/o problems but when it executes
the SP I get the following:

System.Data.SqlClient.SqlException: Invalid length parameter passed to
the substring function.

I change nothing but the login. Same store procedure, same parameters.

Any ideas?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 02:19 PM
Dan Guzman
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

Check the proc (or invoked trigger) to see SUSER_SNAME() is being parsed
into separate domain/account components. The code may fail with a standard
SQL Security connection because a '\' is assumed to be present.

--
Happy Holidays

Dan Guzman
SQL Server MVP

"ZRexRider" <jerryg@ptd.net> wrote in message
news:1135358521.631291.106350@g44g2000cwa.googlegr oups.com...
> Hi,
>
> I have a .NET application that connects to a SQL 2000 database using
> trusted security. It eventually calls a stored procedure that receives
> 3 parameters - nothing special.
>
> If I simply change the connection string to use a valid Userid and
> Password it still connects to the DB w/o problems but when it executes
> the SP I get the following:
>
> System.Data.SqlClient.SqlException: Invalid length parameter passed to
> the substring function.
>
> I change nothing but the login. Same store procedure, same parameters.
>
> Any ideas?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 02:19 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

ZRexRider (jerryg@ptd.net) writes:
> I have a .NET application that connects to a SQL 2000 database using
> trusted security. It eventually calls a stored procedure that receives
> 3 parameters - nothing special.
>
> If I simply change the connection string to use a valid Userid and
> Password it still connects to the DB w/o problems but when it executes
> the SP I get the following:
>
> System.Data.SqlClient.SqlException: Invalid length parameter passed to
> the substring function.
>
> I change nothing but the login. Same store procedure, same parameters.
>
> Any ideas?


A Christmas quiz? Maybe you should try rec.games.trivia in such case.

If this is not meant to be a quiz, please show us the code you are
having problem with, both the ADO .Net code and the stored procedure.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 02:19 PM
ZRexRider
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

Dan you nailed it - SUSER_SNAME() in my trigger blows up because there
isn't a '\' and I didn't code for it.

Happy Holidays to you as well!


Dan Guzman wrote:
> Check the proc (or invoked trigger) to see SUSER_SNAME() is being parsed
> into separate domain/account components. The code may fail with a standard
> SQL Security connection because a '\' is assumed to be present.
>
> --
> Happy Holidays
>
> Dan Guzman
> SQL Server MVP
>
> "ZRexRider" <jerryg@ptd.net> wrote in message
> news:1135358521.631291.106350@g44g2000cwa.googlegr oups.com...
> > Hi,
> >
> > I have a .NET application that connects to a SQL 2000 database using
> > trusted security. It eventually calls a stored procedure that receives
> > 3 parameters - nothing special.
> >
> > If I simply change the connection string to use a valid Userid and
> > Password it still connects to the DB w/o problems but when it executes
> > the SP I get the following:
> >
> > System.Data.SqlClient.SqlException: Invalid length parameter passed to
> > the substring function.
> >
> > I change nothing but the login. Same store procedure, same parameters.
> >
> > Any ideas?
> >


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 02:19 PM
ZRexRider
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

How can I make the following trigger work on both Trusted and
non-trusted connections?

CREATE TRIGGER trIU_tblTest
ON dbo.tblTest
FOR INSERT, UPDATE AS
BEGIN
DECLARE @strUserName VARCHAR(20)

SET NOCOUNT ON
SET ANSI_WARNINGS OFF
-- only want the userlogon name portion
SELECT @strUserName =
right(suser_sname(),CHARINDEX('\',REVERSE(suser_sn ame()))-1)
UPDATE
tbTest
SET
UpdateUserName=@strUserName,
UpdateDate=GETDATE()
WHERE
tblTest.ID IN (SELECT inserted.ID FROM inserted)
SET NOCOUNT OFF
END

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 02:19 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

ZRexRider (jerryg@ptd.net) writes:
> How can I make the following trigger work on both Trusted and
> non-trusted connections?
>
> CREATE TRIGGER trIU_tblTest
> ON dbo.tblTest
> FOR INSERT, UPDATE AS
> BEGIN
> DECLARE @strUserName VARCHAR(20)
>
> SET NOCOUNT ON
> SET ANSI_WARNINGS OFF
> -- only want the userlogon name portion
> SELECT @strUserName =
> right(suser_sname(),CHARINDEX('\',REVERSE(suser_sn ame()))-1)


DECLARE @username nvarchar(256)
SELECT @username = SYSTEM_USER
IF charindex('\', @username) > 0
SELECT @username = substr(@username, charindex('\', @username) + 1,
len(@username)





--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-29-2008, 02:19 PM
ZRexRider
 
Posts: n/a
Default Re: Stored Procedure only works in when app uses trusted security

Thank You Erland - Merry Christmas to you!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:04 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com