|
jp2buzz -> RE: Pocket PC w/ SQL Server 2000 and 2005 (3/4/2008 12:00:05 PM)
|
Hi Mr. Vickers. I actually followed your code for connecting. :) I used it to check that I am connected to a network, then used your SqlException technique to get the specifics of the error. I created a very stripped down version of my code, and it stills throws the SqlException. Here is the actual code, that will probably work great for most people:Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Net
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Public Class Class1
Private strSql9th As String = "Persist Security Info=False;Integrated Security=False;" & _
"Server=CPAPP,1433;Initial Catalog=AIO;User ID=public;password=public;"
Public sqlConn As New SqlConnection(strSql9th)
Sub Main()
Dim connected As Boolean = Connected_To_Network()
If (connected = True) Then
Try
sqlConn.Open()
Catch ex As SqlException
' SQL Exception Reader routine (START)
Dim i As Integer
Dim msgFmt As String = "Error {0}: {1}" + vbCrLf + vbCrLf + "Source: {2}" + vbCrLf + vbCrLf + "Call: {3}"
Dim ttlFmt As String = "Error {0} of {1} - Level {2}"
For i = 1 To ex.Errors.Count
Dim msg As String
Dim ttl As String
With ex.Errors(i - 1)
msg = String.Format(msgFmt, .LineNumber + 1, .Message, .Source, .Procedure)
ttl = String.Format(ttlFmt, i, ex.Errors.Count, .Class)
End With
Dim dr As Windows.Forms.DialogResult = _
MessageBox.Show(msg + vbCrLf + vbCrLf + "Exit Application?", ttl, _
MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1)
If (dr = Windows.Forms.DialogResult.Yes) Then
connected = False
Application.Exit()
End If
Next i
' SQL Exception Reader routine (END)
Finally
sqlConn.Close()
End Try
End If
If (connected = True) Then
Dim PackageManager As New frmScanPackout
PackageManager.ShowDialog()
End If
End Sub
Public Function Connected_To_Network() As Boolean
Dim ipAddress() As System.Net.IPAddress = Dns.GetHostEntry(Dns.GetHostName()).AddressList
Dim localEndPoint As IPEndPoint = New IPEndPoint(ipAddress(0), 0)
Try
If localEndPoint.Address.ToString = "127.0.0.1" Then
Return False
Else
Return True
End If
Catch ex As Exception
Return False
End Try
End Function
End Class What would cause Sql2000 to refuse the login? Is PPC refusing to connect to Sql2000? Is there a way to get more detailed information about this error whenever it happens? I've tried looking in the Sql2000 message log, but I haven't found anything there.
|
|
|
|