I get an error when I attempt to connect to SQL Express using VB.net. I am attempting to use a System DSN previously created using the ODBC Data Source Administrator. The DSN was tested using MS Access by linking the tables. (Inserts... Updates and etc. all working) The code that fails is when I use opt1 as the connection string. opt2 works. SQL Express is installed locally and running. SQL Browser is also running. ALL protocols are enabled in the SQL Server Configuration manager. No firewall on.
OS is VISTA Home Premium SP1
Here is my Code:
Dim conn As New SqlClient.SqlConnection() : Dim cmd As New
SqlClient.SqlCommand()
opt1 = "Data Source=myDSN_Name;Initial Catalog=" & Me.dbname.ToString & User Id=" & Me.Usr.ToString & ";Password=" & Me.pwd.ToString & ";" opt2 = "Server=myMachineName\sqlexpress;Initial Catalog=" & Me.dbname.ToString & User Id=" & Me.Usr.ToString & ";Password=" & Me.pwd.ToString & ";" conn.ConnectionString = IIf(Me.option1.Checked, opt1.ToString,
opt2.ToString)
conn.Open()
cmd.Connection = conn
cmd.CommandText = inSQL
cmd.ExecuteNonQuery()
The error thrown for opt1 is:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
(provider: TCP Provider, error: 0 - No such host is known.)
Any and all help appreciated.
OS is VISTA Home Premium SP1
Here is my Code:
Dim conn As New SqlClient.SqlConnection() : Dim cmd As New
SqlClient.SqlCommand()
opt1 = "Data Source=myDSN_Name;Initial Catalog=" & Me.dbname.ToString & User Id=" & Me.Usr.ToString & ";Password=" & Me.pwd.ToString & ";" opt2 = "Server=myMachineName\sqlexpress;Initial Catalog=" & Me.dbname.ToString & User Id=" & Me.Usr.ToString & ";Password=" & Me.pwd.ToString & ";" conn.ConnectionString = IIf(Me.option1.Checked, opt1.ToString,
opt2.ToString)
conn.Open()
cmd.Connection = conn
cmd.CommandText = inSQL
cmd.ExecuteNonQuery()
The error thrown for opt1 is:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
(provider: TCP Provider, error: 0 - No such host is known.)
Any and all help appreciated.