Opening database connection
-
Hi, I have the following code which I converted fro c#. Any time I run it I get an error at the con.open() This is the error An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Here is the code
Private Sub LookupDB(ByVal PartNum As String) Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******" Dim con As SqlConnection = New SqlConnection(ConnectString) Dim cmd As SqlCommand = New SqlCommand("pGetSWEETFileAttributes", con) cmd.CommandType = CommandType.StoredProcedure ' ' Initialise parameters to database stored procedure: ' ' 1. Input Parameter representing Part Number ' Dim param As SqlParameter = New SqlParameter("@inparam_ElementID", SqlDbType.VarChar, 50) param.Direction = ParameterDirection.Input param.Value = PartNum cmd.Parameters.Add(param) ' ' Read from database ' con.Open() Dim reader As SqlDataReader = cmd.ExecuteReader() 'ExecuteNonQuery(); Dim record_count As Integer = 0 While reader.Read() txtSize.Text = reader("FileSize").ToString() txtMD5.Text = reader("MD5Checksum").ToString() record_count = record_count + 1 End While reader.Close() con.Close() If record_count = 0 Then Throw New Exception("Part number " + PartNum + " not found in dataMyBase. Please enter the filesize and MD5 checksum") End If End Sub
-
Hi, I have the following code which I converted fro c#. Any time I run it I get an error at the con.open() This is the error An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Here is the code
Private Sub LookupDB(ByVal PartNum As String) Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******" Dim con As SqlConnection = New SqlConnection(ConnectString) Dim cmd As SqlCommand = New SqlCommand("pGetSWEETFileAttributes", con) cmd.CommandType = CommandType.StoredProcedure ' ' Initialise parameters to database stored procedure: ' ' 1. Input Parameter representing Part Number ' Dim param As SqlParameter = New SqlParameter("@inparam_ElementID", SqlDbType.VarChar, 50) param.Direction = ParameterDirection.Input param.Value = PartNum cmd.Parameters.Add(param) ' ' Read from database ' con.Open() Dim reader As SqlDataReader = cmd.ExecuteReader() 'ExecuteNonQuery(); Dim record_count As Integer = 0 While reader.Read() txtSize.Text = reader("FileSize").ToString() txtMD5.Text = reader("MD5Checksum").ToString() record_count = record_count + 1 End While reader.Close() con.Close() If record_count = 0 Then Throw New Exception("Part number " + PartNum + " not found in dataMyBase. Please enter the filesize and MD5 checksum") End If End Sub
johnjsm wrote:
Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******"
I assume this is not the actual code, you changed it to post it ?
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )