473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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?

Dec 23 '05 #1
6 2683
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" <je****@ptd.net> wrote in message
news:11**********************@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?

Dec 23 '05 #2
ZRexRider (je****@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, es****@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
Dec 23 '05 #3
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" <je****@ptd.net> wrote in message
news:11**********************@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?


Dec 24 '05 #4
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

Dec 24 '05 #5
ZRexRider (je****@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, es****@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
Dec 24 '05 #6
Thank You Erland - Merry Christmas to you!

Dec 26 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
6
by: Martin Feuersteiner | last post by:
Dear Group I have found that table A had SELECT permissions for 'Public' but not table B. Giving 'Public' SELECT permissions on table B did the trick. HOWEVER, I don't want anyone to be able...
1
by: Brad H McCollum | last post by:
I'm writing an application using VB 6.0 as the front-end GUI, and the MSDE version of SQL Server as the back-end (it's a program for a really small # of users --- less then 3-4). I'm trying to...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
6
by: Wojciech Wendrychowicz | last post by:
Hello to All, I'm trying to retrieve records from AS/400 in an VBA application. So, I've made an RPG program, then a stored procedure wchich calls that RPG program, and finally some VBA code to...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.