1

SQLAPI++ を使用してプログラムをデータベースに接続しています。

次のコードは、エラーなしでコンパイルされます。ただし、データベースには接続しません。次のようなエラーが表示されます。

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)
ExecuteNonQuery requires an open and available Connection. 
The connection's current state is closed.

サーバーでリモート接続が有効になっており、TCI/IP が有効になっていることを確認しました。また、ファイアウォールにポート例外を追加しようとしましたが、ファイアウォールをオフにしようとしても失敗しました。-そして私のウイルス対策。

だから、これは私のコードと関係があると思います。誰でも何か間違ったことを見つけることができますか?

#include <iostream>
#include "SQLAPI\include\SQLAPI.h"
#include <string>
#include <Windows.h>


using namespace std;

int main(int argc, char* argv[])
{

SAConnection con; 

try
{ 
    con.Connect(

    "BLAKE\\SQLEXPRESS@ERP",     // db *& server?!*
        "sa",   // user
        "blake",   // password
    SA_SQLServer_Client);



}
catch (SAException &x)
{
    // SAConnection::Rollback()

    try
    {
        // on error rollback changes
        con.Rollback();
    }
    catch (SAException &)
    {
    }

    cerr << (const char*)(x.ErrText()) << endl;

}



return 0;
}
4

2 に答える 2

1

この例外は、sqlServer サービスが停止したとき、または TCP ポートが変更されたときにスローされるため、それを確認してください。

于 2014-04-19T10:25:46.210 に答える