naqayya
asked on
Run stored proc using 'sa' login causes write conflict
I have a SQL Server 2000 db connected to an Access Project (.adp) front-end.
My front-end has forms with buttons that users click on to perform calculations and update data on the form. The code behind the buttons are in VB and execute stored procedures that update fields.
I make the connection in the VB code using:
myCmd.ActiveConnection = "Provider = SQLOLEDB; Data Source = server; Initial Catalog = database; User ID = sa; Password=;"
The problem I get is that everytime a user runs the code and the record is updated, the user gets the message:
Write Conflict: The record has been changed by another user since you started editing it...
Each user has their own UserName, so that is why I get the message because it has been updated by 'sa'.
How do I get around this? I don't want to connect as the user as their passwords may change, etc.
Thanks.
My front-end has forms with buttons that users click on to perform calculations and update data on the form. The code behind the buttons are in VB and execute stored procedures that update fields.
I make the connection in the VB code using:
myCmd.ActiveConnection = "Provider = SQLOLEDB; Data Source = server; Initial Catalog = database; User ID = sa; Password=;"
The problem I get is that everytime a user runs the code and the record is updated, the user gets the message:
Write Conflict: The record has been changed by another user since you started editing it...
Each user has their own UserName, so that is why I get the message because it has been updated by 'sa'.
How do I get around this? I don't want to connect as the user as their passwords may change, etc.
Thanks.
ASKER
Thanks KMAN:
My front-end doesn't take a username and password, but uses the Windows login to get the UserName and then give appropriate permissions.
I have a procedure to get the Windows UserName, but how do I get the password? I don't want to make the users login twice.
I use the following code to get the UserName:
-------------------------- ---------- ---------- ---------- ---
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function o_CurrentNTUser() As String
Dim strUserName As String * 25
Dim intReturn As Integer
intReturn = GetUserName(strUserName, 25)
strUserName = Trim(Left(strUserName, InStr(1, strUserName, Chr(0)) - 1))
o_CurrentNTUser = Trim(strUserName)
End Function
-------------------------- ---------- ---------- ---------- ---
Thanks.
My front-end doesn't take a username and password, but uses the Windows login to get the UserName and then give appropriate permissions.
I have a procedure to get the Windows UserName, but how do I get the password? I don't want to make the users login twice.
I use the following code to get the UserName:
--------------------------
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function o_CurrentNTUser() As String
Dim strUserName As String * 25
Dim intReturn As Integer
intReturn = GetUserName(strUserName, 25)
strUserName = Trim(Left(strUserName, InStr(1, strUserName, Chr(0)) - 1))
o_CurrentNTUser = Trim(strUserName)
End Function
--------------------------
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A bit off the track, but i thought that the user name can also be retreived in much simpler way, in VB, as follows:
strUserName = Environ("UserName")
You can also get the domain name by Environ("UserDomain")
strUserName = Environ("UserName")
You can also get the domain name by Environ("UserDomain")
ASKER
Thanks NitinSontakke: yes you're right!
Make a form where the User logs in (or registry setting, INI file, etc.), store the ID and password in a variable, then pass them to the connection string, instead of using the hard-coded 'sa' whihch is a System Administrator ID and should NOT be used to add/change/delete data.
Like:
myCmd.ActiveConnection = "Provider = SQLOLEDB; Data Source = server; Initial Catalog = database; User ID=" & strUser & ";Password=" & strPwd & ";"
Got the idea?
K