Solved

Run stored proc using 'sa' login causes write conflict

Posted on 2002-06-26
5
189 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:naqayya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:KMAN
ID: 7110529
You are connecting as 'sa' regardless of any other login since it is hard coded in your connection string!

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
0
 

Author Comment

by:naqayya
ID: 7110585
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.
0
 
LVL 5

Accepted Solution

by:
KMAN earned 100 total points
ID: 7110675
I doubt there is a way to retrieve the password, like the UID.  You may try to setup a SQL Server ODBC datasource, set it to use Windows Authentication and then use a connection string like:

myCmd.ActiveConnection = "mySQLServer"


...where mySQLServer is the ODBC datasource name.

Then the individual PC's will authenticate SQLServer with the correct UID/PWDs
0
 
LVL 9

Expert Comment

by:Nitin Sontakke
ID: 7110724
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")

0
 

Author Comment

by:naqayya
ID: 7110789
Thanks NitinSontakke: yes you're right!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bit defender blocks good applications 2 115
Set email body to html using vbscript 6 89
How to read File Date Created using VB6 8 70
Sub or Function is not defined 6 59
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question