Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net sqlconnection中的数据源无效_Asp.net_Sql Server 2008_Vps - Fatal编程技术网

Asp.net sqlconnection中的数据源无效

Asp.net sqlconnection中的数据源无效,asp.net,sql-server-2008,vps,Asp.net,Sql Server 2008,Vps,我有一个asp.net网站,在我的本地计算机上运行良好,它具有创建和打开连接的功能(sql server 2008 R2) 我买了一个VPS,我上传了我的源代码,当我调用这个函数时,它无法连接到数据库,因为数据源是错误的! 这是它收到的错误: {System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection t

我有一个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;");
    }
但它无法连接到数据库!我的代码出了什么问题?我的错误是什么?

试试这个:

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;