I have a problem when accessing a SQL server from my VB application. Everything works fine on my test environment but when I was installing the application on the target environment I get the following error:
Login failed for user 'UserName'.
Reported by: Microsoft OLE DB Provider for SQL Server
Help Context ID: 0 :
This looks like the user doesn't have rights to the database, but what my problem is that when the same user uses the program on a different computer it works!?
I've tried to create an ODBC connection on the computer that cannot access the database and that works.
My code allows me to choose either to use ODBC or connect straight towards the database using trusted connection, no one works.
Here are my code for opening the database:
Public Function OpenDatabase() As Boolean
On Error GoTo ErrorHandler
Set moConnect = New ADODB.Connection
moConnect.CommandTimeout = 600
If bUseODBC Then
.Mode = adModeReadWrite
.ConnectionString = "Provider=sqloledb;server=" + sServer + "; database=" + sName + "; Trusted_Connection=yes"
.CursorLocation = adUseClient
OpenDatabase = True
Dim objError As ADODB.Error
Dim strError As String
If Err.Number = -2147467259 Then
If moConnect.Errors.Count > 0 Then
For Each objError In moConnect.Errors
strError = "Error #" & objError.Number & _
" " & objError.Description & vbCrLf & _
"NativeError: " & objError.NativeError & vbCrLf & _
"SQLState: " & objError.SQLState & vbCrLf & _
"Reported by: " & objError.Source & vbCrLf & _
"Help file: " & objError.HelpFile & vbCrLf & _
"Help Context ID: " & objError.HelpContext
DebugPrintError "OpenDatabase", , strError
DebugPrintError "OpenDatabase", Err.Number, Err.Description + " " + Err.Source
OpenDatabase = False