2012-09-18 106 views
0

我有一个asp.net网站,我的本地计算机上工作得很好,它有一个函数来创建和打开连接(SQL服务器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;"); 
    } 

但它无法连接到数据库!什么是错我的代码?什么是我的错?

回答

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; 

OR

Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False; 
+0

坦,它解决了我的问题:) –