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などの宣言を変更するだけです。

関連する問題