我有一个在我的本地计算机上运行良好的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;");
}但是它无法连接到数据库!我的代码出了什么问题?我的错误出在哪里?
发布于 2012-09-18 15:51:32
试试这个:
con = new SqlConnection("Server=209.54.48.101;Database=Ranker;User ID=sa;Password=*****;Trusted_Connection=False;Integrated Security=False;");SQL Server2008的连接字符串
标准版安全
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername; Password=myPassword;或
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;https://stackoverflow.com/questions/12472333
复制相似问题