我是否必须在其他地方添加连接字符串,就像我们在Asp.net中的web配置中那样,但在vb.net windows窗体中,我找不到像web配置这样的内容 以下是连接代码......
y
答案 0 :(得分:2)
它不起作用,因为你是' Newing'分配连接字符串后的SqlConnection。
这是您当前的代码;
Dim Conn As New SqlConnection
Conn.ConnectionString = "Data Source=Abc;Initial Catalog=Test_Database;Integrated Security=True"
Conn = New SqlConnection
' If Conn Is Nothing Then
If Conn.State = ConnectionState.Open Then
MsgBox("Connected")
Else
MsgBox("Not Connected")
但是你必须取出连接字符串的第二个新内容,应该是这样的;
Dim Conn As New SqlConnection
Conn.ConnectionString = "Data Source=Abc;Initial Catalog=Test_Database;Integrated Security=True"
' If Conn Is Nothing Then
If Conn.State = ConnectionState.Open Then
MsgBox("Connected")
Else
MsgBox("Not Connected")