Error connection to database

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:

Error #-2147217843 Login failed for user 'UserName'.
NativeError: 18456
SQLState: 42000
Reported by: Microsoft OLE DB Provider for SQL Server
Help file:
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
'DebugPrint "OpenDatabase"
Set moConnect = New ADODB.Connection
moConnect.CommandTimeout = 600
If bUseODBC Then
moConnect.Open sDSN
With moConnect
.Mode = adModeReadWrite
.ConnectionString = "Provider=sqloledb;server=" + sServer + "; database=" + sName + "; Trusted_Connection=yes"
.CursorLocation = adUseClient
End With
End If

OpenDatabase = True
Exit Function
Dim objError As ADODB.Error
Dim strError As String
If Err.Number = -2147467259 Then
Resume Next
End If

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
End If
DebugPrintError "OpenDatabase", Err.Number, Err.Description + " " + Err.Source
OpenDatabase = False

End Function

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!