0

코드를 통해 Visual Studio 프로젝트에서 SQL Server 데이터베이스에 연결하려고합니다. 이미 SQL Server 데이터베이스가 서버 탐색기를 통해 데이터 연결로 추가되었지만. 내 코드에는 오류가 없지만 버튼 클릭 후 프로젝트를 실행하면 내 sqlConnection.Open()에 오류가 발생합니다. 서버 탐색기의 SQL Server 데이터베이스 속성에서 연결 문자열을 복사했습니다. SQL Server는 원격 연결을 허용하도록 구성됩니다. 서버 탐색기에서 데이터베이스 연결에 오류가 없습니다. 이것은 내가 받고있는 오류입니다 :SqlConnection.Open() 처리되지 않은 예외 오류 Visual Studio 2015 커뮤니티 버전

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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)

다음은 데이터베이스 연결을 설정해야하는 코드입니다.

어떤 도움은 매우 유용하고 나는 그것이

Imports System.Data.SqlClient 

Public Class Add_Customer 
    'setup SQL connection' 

    Dim sqlConnection1 As New SqlConnection("server=192.168.0.205;user id=bill;persistsecurityinfo=True;database=new_schema") 
    Dim cmd As New SqlCommand 
    Dim reader As SqlDataReader 
    Public Customer_Name, Phone_Num, Cust_Contact As String 

    Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click 

     cmd.CommandText = "insert_customer" 
     cmd.CommandType = CommandType.StoredProcedure 
     cmd.Connection = sqlConnection1 

     sqlConnection1.Open() 

     Customer_Name = CustNametxt.Text 
     Phone_Num = PhoneNumtxt.Text 
     Cust_Contact = CustomerContact.Text 

     Console.WriteLine(CustNametxt) 
     Console.WriteLine(PhoneNumtxt) 
     Console.WriteLine(CustomerContact) 

     reader = cmd.ExecuteReader() 

     sqlConnection1.Close() 
    End Sub 
End Class  
+0

방화벽, 방화벽, 모든 방화벽을 확인하십시오. 포트 차단을 해제하고 포트가 깨끗한 지 다시 확인한 다음 맥주를 가져갑니다. 간단히 말해 방화벽을 확인하십시오 * (스파이더 맨 만화 테마 조정) * –

+0

@ Laughing-Vergil 차단을 해제해야하는 특정 포트가 있습니까? 아니면 모두 차단 해제해야합니까? 또한 가서 맥주 라인을 만들어 줄게 나 그리고 나는 또한 이러한 변화를하기 전에 맥주를 마시고있다 :) – SkylarPurifoy

답변

0

문제는 우리가 사용하고있는 데이터베이스는 MySQL 데이터베이스입니다이었다 주셔서 감사합니다. 그래서 우리가해야만하는 것은 MySQLCommand, MySQLConnection 등으로 선언을 변경하는 것입니다.

관련 문제