Howdy, Stranger!

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

Categories

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
Else
With moConnect
.Mode = adModeReadWrite
.ConnectionString = "Provider=sqloledb;server=" + sServer + "; database=" + sName + "; Trusted_Connection=yes"
.Open
.CursorLocation = adUseClient
End With
End If

OpenDatabase = True
Exit Function
ErrorHandler:
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
Next
End If
DebugPrintError "OpenDatabase", Err.Number, Err.Description + " " + Err.Source
OpenDatabase = False

End Function


Comments

  • Justin BibJustin Bib USAMember Posts: 0

    ______ | http://forcoder.org | free video tutorials and ebooks about { Perl, PL/SQL, Go, Assembly, Objective-C, JavaScript, C, Java, Delphi, Python, C++, C#, MATLAB, R, Visual Basic .NET, Scratch, Swift, Ruby, PHP, Visual Basic Kotlin, Logo, Awk, Transact-SQL, ML, Lisp, Dart, COBOL, Lua, Rust, Erlang, Julia, Scala, LabVIEW, Clojure, VBScript, Crystal, Scheme, FoxPro, Prolog, D, F#, ABAP, Ada, SAS, Apex, Fortran, Bash, Hack, Alice } _________

Sign In or Register to comment.