fifamaniac04
fifamaniac04

Reputation: 2383

ASP.NET Connection string error when using ip address

I'm trying to debug an ASP.NET page I have trying to connect to a local SQLServer DB, when the connection string I'm using has the name of the local machine, it works fine like in below

string ConnectionString = "Integrated Security=SSPI;" +
                                  "Initial Catalog=ARTICLEDB;" + 
                                  "Data Source=MYMACHINENAME\\MYSQLSVR;";

... later on...

        conn = new SqlConnection(ConnectionString);
        // Open the connection
        try
        {
            if (conn.State != ConnectionState.Open)
            {
                conn.Open(); 
                //don't work here when using ##.##.##.##\MYSQLSVR as datasource
            }

            return true;
        }
        catch
        {
            return false;
        }

when I use the IP machine as the value for the datadource such as: ###.###.###.###\\\MYSQLSVR the I get an exception saying:

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: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol)

This problem originated from trying to run the site from IIS and getting a similar error where the connection was not opened.

How can I reference the DB in the connection string so that IIS can find the DB?

I've also tried adding the connection string in IIS for the site but not sure how to reference that IIS connection string from my project/site

Upvotes: 0

Views: 3711

Answers (2)

Irfan TahirKheli
Irfan TahirKheli

Reputation: 3662

Check the following it is working for me.

Data Source=190.190.200.100,1433;Initial Catalog=DBName;Integrated Security=False;user id=userid;password=password

Upvotes: 0

Damith
Damith

Reputation: 63095

go to SQL Server Configuration Manager and turn on "Named Pipes" and "TCP/IP"

and your connection string should look like below

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

http://www.connectionstrings.com/sql-server-2008

Upvotes: 1

Related Questions