Dim source As String = "server = local;" + "integrated security = SSPI;" + "database = MyDataBase" Dim selectstr As String = "SELECT [Name], [Password] FROM [UserTable]"
Try Dim conn As SqlConnection = New SqlConnection(source) conn.Open() ''走到这里报错
Dim cmd As SqlCommand = New SqlCommand(selectstr, conn) Dim rowsReturned As Integer = cmd.ExecuteNonQuery() Console.WriteLine("{0} rows affect!") conn.Close() Console.WriteLine() Catch ex As Exception Console.WriteLine("12312312") Console.Read End Try
数据库名:MyDataBase 报错 内容:A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
------解决方案-------------------- 大概看了一下意思,它说服务器没连上,让你检查一下是否允许远程连接
------解决方案-------------------- server = .;OK
------解决方案--------------------