0

我有一个在我的本地计算机上运行良好的 asp.net 站点,它具有创建和打开连接的功能(sql server 2008 R2)连接数据库,因为数据源错误!这是它收到的错误:

    {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 回答