Arash khangaldi
Arash khangaldi

Reputation: 110

Data source in sqlconnection not valid

I have a asp.net site that works fine on my local computer,it has a function to create and open connection (sql server 2008 R2) I bought a VPS and I uploaded my source in it, when I call the function it fails to connect to data base because the data source is wrong! it's the error it recieve:

    {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)

Here is my code which works on my computer:

    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();

    }

when I uploaded my source to my VPS I changed the Data source to my 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;");
    }

But it can't connect to data base!what is wrong with my code?what's my mistake?

Upvotes: 0

Views: 1118

Answers (1)

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Try this:

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

Connection strings for SQL Server 2008

Standard Security

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

OR

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

Upvotes: 1

Related Questions