0

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

2
  • Your port may be blocked. Check your firewall settings. Try Data Source=localhost. Commented Sep 27, 2013 at 0:03
  • are you configure SQL Server authentication in mix mode? Commented Oct 1, 2013 at 5:00

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Where can I check to see that the default port of 1443 did not change? I am still not being able to connect and now I'm thinking there could be an issue with my firewall
check Link1 and Link2
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.