0

ローカルコンピューターで正常に動作するasp.netサイトがあり、接続を作成して開く機能があります(sql server 2008 R2)VPSを購入し、ソースをアップロードしましたが、関数を呼び出すと失敗しますデータソースが間違っているため、データベースに接続してください。それはそれが受け取るエラーです:

    {System.Data.SqlClient.SqlException: 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)

これが私のコンピューターで動作する私のコードです:

    public ClientHandle()
    {
        SqlConnection con = new SqlConnection("Server=localhost;Data Source=ARASH-PC;User ID=sa;password=*****;Initial Catalog=Ranker;Trusted_Connection=False;Integrated Security=False;");
     con.open();

    }

ソースをVPSにアップロードしたときに、データソースをIPに変更しました。

    public ClientHandle()
    {
        con = new SqlConnection("Server=localhost;Data Source=209.54.48.101;User ID=sa;password=*****;Initial Catalog=Ranker;Trusted_Connection=False;Integrated Security=False;");
    }

しかし、データベースに接続できません!私のコードの何が問題になっていますか?私の間違いは何ですか?

4

1 に答える 1

1

これを試して:

con = new SqlConnection("Server=209.54.48.101;Database=Ranker;User ID=sa;Password=*****;Trusted_Connection=False;Integrated Security=False;");

SQL Server 2008 の接続文字列

標準セキュリティ

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername; Password=myPassword;

また

Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
于 2012-09-18T07:51:32.090 に答える