Login failure...

  • Thread starter Thread starter Rob R. Ainscough
  • Start date Start date
R

Rob R. Ainscough

I ran my code against my LOCAL SQL Server database -- all works.

I run the code against a remote SQL Server providing the correct uid and
password, and I get Login failure. What is more bizarre, if I step thru the
code in VS.NET (exact same code with same connection values), I don't get
the error??

If I exit VS.NET and run the .EXE (managed) by itself, I get the error?

I'm at a total loss, I don't even know where to turn to try and debug (as
everything works when I debug) -- any suggestions?

Rob.
 
Hello Rob,

Check out the code below and in your appilcation make sure your suspect code
is in a Try, Catch block. You Should Be able to Copy and Paste, let me know
if this helps
'**********************************************************
'** Example For Your Code
'**********************************************************
Private Sub MyMethod
Try

Catch ex As Exception
WriteToErrorLog("MyMethod", ex.Message & vbCrlf & vbCrlf &
ex.StackTrace
End Try
End Sub
'**********************************************************
'** This Function Get The AppPath(Not The Bin, but the Project Folder)
'**********************************************************
Public Shared Function GetAppPath() As String
If Not Right(Microsoft.VisualBasic.CurDir.Replace("bin", ""), 1) =
"\" Then
Return Microsoft.VisualBasic.CurDir.Replace("bin", "") & "\"
Else
Return Microsoft.VisualBasic.CurDir.Replace("bin", "")
End If
End Function

'**********************************************************
'** This Method Will Write Any Errors To The ErrorLog Folder In Your Project
Folder
'**********************************************************
Public Shared Sub WriteToErrorLog(ByVal Sender As String, ByVal Message As
String)

Try
Dim FilePath As String = GetAppPath() & "ErrorLog\ErrorLog" &
Microsoft.VisualBasic.DateAndTime.Month(Now).ToString &
Microsoft.VisualBasic.DateAndTime.Day(Now).ToString & Year(Now).ToString &
".txt"
Dim SWriter As System.IO.StreamWriter

If System.IO.Directory.Exists(GetAppPath() & "ErrorLog") = False
Then System.IO.Directory.CreateDirectory(GetAppPath() & "ErrorLog")

If System.IO.File.Exists(FilePath) = False Then

SWriter = System.IO.File.CreateText(FilePath)

SWriter.WriteLine("*****************************************")

SWriter.WriteLine("** SENDER: " & Sender)

SWriter.WriteLine("** ERROR: " & Message)

SWriter.WriteLine("*****************************************")

SWriter.Flush()

SWriter.Close()

Else

SWriter = System.IO.File.AppendText(FilePath)

SWriter.WriteLine("*****************************************")

SWriter.WriteLine("** SENDER: " & Sender)

SWriter.WriteLine("** ERROR: " & Message)

SWriter.WriteLine("*****************************************")

SWriter.Flush()

SWriter.Close()

End If

Catch ex As Exception

MsgBox("There was a problem writing to the Error Log." & vbCrLf
& vbCrLf & "Please report this to World Touch Interactive.",
MsgBoxStyle.Exclamation, "Error Writing To File")
Application.Exit()

End Try
End Sub
 
I do write to the EventLog, and I can see the error message in the event
log -- that's where it suggests "Login failure..." and even tells me the
function, I add variable info to the EventLog and all is good. But like I
said, if I run the same code in debug mode (stepping thru the code), I don't
get any errors.

So, I'm thinking this is a timing problem with connections to the my SQL
Server, I can connect and disconnect rapidly in succession (usually in a
loop) -- I'm suspecting the connection overhead with rapid
connects/disconnects is the cause -- this is the ONLY thing I can come up
with as it obviously appears to be a timing issue. Also, the fact that the
same code going against a local SQL Server on my same PC does NOT produce
any errors (debug or just running the code) would also point towards
connection/disconnect timing problem (i.e. my remote SQL Server can't keep
up or something).

Does the SQL Server produce any events that I could check to see what
problems it maybe reporting?

I'm going to try to code my connection processing differently and see if
this resolves it.

Rob.
 
Change the timeout property and you could montior SQL Server with the SQL
Profiler auditing login's, failed logins, connections ect
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top