Here is my code in vb.net below. The problem with this connection string is that the system reads it, compiles it but when I'm trying to pass any input into the database it tells me network instance error.
You see here the original code for the connection:
Module MyFunction
Public cnn As SqlClient.SqlConnection
Public Sub MakeConnection()
cnn = New SqlClient.SqlConnection
If Not cnn.State = ConnectionState.Open Then
cnn.ConnectionString = System.IO.File.ReadAllText(Application.StartupPath & "\cnn.txt")
cnn.Open()
End If
This gives me error that "executereader is not initialized"
So I changed it like this:
Public cnn As SqlClient.SqlConnection
Public Sub MakeConnection()
cnn = New SqlClient.SqlConnection("Data Source=USARES-PC\SQLEXPRESS;Initial Catalog=HotelDB;Integrated Security=True")
cnn.Open()
' MessageBox.Show("Connection opened!")
End Sub
I also tried this way:
Public cnn As SqlClient.SqlConnection
Public Sub MakeConnection()
If cnn.State = ConnectionState.Open Then
cnn.ConnectionString = "Data Source=USARES-PC\SQLEXPRESS;Initial Catalog=HotelDB;Integrated Security=True"
cnn.Close()
End If