2016-03-30 25 views
0

.NET接続文字列を使用してSQL Anywhere 12データベースに接続するのは本当に苦労しています。.NET接続文字列を使用してリモートSQL Anywhere 12データベースに接続

私は、次のクエリ文字列を使用しています:

Data Source=xxx.xxx.xxx.xxx,yyyy; Initial Catalog={MyDatabaseName}; User ID={MyUsername}; Password={MyPassword} 

I(xxx.xxx.xxx.xxxは=リモートサーバとYYYYのIPアドレスが必要なポートがある場合)私は次のエラーを受信して​​います、これを実行すると、しかし

private const string connectionString = "{MyQueryString}"; 
private const string testQuery = "{ATestSelectQuery}"; 


using (SqlConnection conn = new SqlConnection(connectionString)) 
{ 
    ExecuteNonQuery(conn, testQuery); 
} 


static void ExecuteNonQuery(SqlConnection conn, string query) 
{ 
    try 
    { 
     using (SqlCommand cmd = new SqlCommand(query, conn)) 
     { 
      cmd.CommandText = query; 
      cmd.CommandType = CommandType.Text; 
      conn.Open(); 
      cmd.ExecuteNonQuery(); 
      conn.Close(); 
     } 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine("ERROR: {0}", ex.Message); 
    } 
} 

:私の接続をテストするには、次のコードでこれを実行しようとしている

ERROR: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

答えて

1

SQLAnywhere 12サーバーではなくMicrosoft SQLサーバーに接続しようとしているようです。 SqlConnection、SqlCommandなどは、Microsoft SQLサーバー専用です。 SQLAnywhere 12の.NETクライアントオブジェクトは、SAConnection、SACommandなどです。

適切なSQLAnywhere .NETクライアントファイルがインストールされていることを確認する必要があります。そうでない、またはわからない場合は、SQL Anywhere Developer Editionをダウンロードしてください。これは無料。クライアントのバージョン12-17は、バージョン12のサーバーに接続します。 SQLAnywhereの接続文字列は、MS SQL Serverの接続文字列と大きく異なることに注意してください。

関連する問題