SQL Server 2008에 데이터베이스가 있으며 Visual Basic 2010에서 코드를 실행하여 연결하려고합니다. 나는 다음과 같은 코드를 가지고 있지만 라인 SQLConn.Open()
에 오류 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
을 얻고있다 :VB2010 : SQL Server 2008에 연결
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim SQLConn As SqlClient.SqlConnection
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim connectionstring As String
connectionstring = "Data Source=MySQLServer\MyInstance;Database=MyDatabase;Integrated Security=true;"
Try
SQLConn = New SqlConnection(connectionstring)
SQLConn.Open()
Catch ex As Exception
MsgBox(ex.Message & " Error Connecting to database!", MsgBoxStyle.Critical)
Exit Sub
End Try
Dim da As SqlDataAdapter
da = New SqlDataAdapter("SELECT * from DR_Users", SQLConn)
Dim dt As DataTable
da.Fill(dt)
For i = 0 To dt.Rows.Count - 1
Dim dr As DataRow = dt.Rows(i)
Debug.Print(dr.Item("UserId").ToString)
Next
End Sub
End Class
편집 : 나는 VBA 코드에 노력하고있다 서버 \ 인스턴스를 알고 데이터베이스 이름이 올바른지 확인합니다.
1) 데이터베이스 서버의 이름은 MySQLServer되지 않습니다 : 그것은 VB.NET에서 2010 년
동료가 작업 한 VB.NET 2010 솔루션을 복사했습니다. 나는 그의 PC에서 테스트를했고 잘 작동했다. 그의 SQL Server 2008 데이터베이스에 액세스 할 수 있고 첫 번째 TableAdapter.Fill 문에서 동일한 오류 메시지가 나타납니다. 데이터 원본 창을 통해 연결할 수 있으며 문제없이 디자인 모드에서 레코드를 미리 볼 수 있지만 한 번 준수하면 레코드를 볼 수 없습니다. 깨끗한 Visual Studio Ultimate 설치를 수행해야합니까? 아니면 패치/핫픽스가 있습니까? – Rick
Visual Studio 2010 제거 유틸리티를 실행하고 다시 설치했지만 여전히 동일한 메시지가 나타납니다. – Rick