I get the following error when trying to connect to SQL Server:
Cannot connect to 108.163.224.173.
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) (Microsoft SQL Server, Error: 1326)
This error is thrown when I try to configure my database to gridview in Visual Studio 2010. I'm at a loss as to how to debug this error.
How would you debug this error? What steps should I take in order to determine what is really going on here, in addition to the one mentioned in the error message?
I was experiencing the same problem and the problem was that I hade several projects in the solution (
Web
andDroid
) and even thoughDefault project
was choosen in thePackage Manager Console
it used the connection string from theDroid
project:After setting the
Startup Project
toWeb
and theDefault Project
inPackage Manger Console
I got it to work.I think you are using the Express Edition
Try to add
"\SQLEXPRESS"
to your server namee.g.
"MY-SERVER\SQLEXPRESS"
I found the following techniques helpful:
Why this error is so boresome and noisy, just because it can occur in varied situation.
I have done all approchs above here, and still being sucked. So make sure u have done the same as me before browsing downward.
Maybe I am not able to fix ur situation instantly, but I can point out a direction or thinking to u(The one who finally slide down here). I have started to ponder the error of my running program occurring after I made sure that the instance name is clearly right and set my database to allow remote control following the methods above. After then, I suspected something wrong happening in my code snippet of SQL connection.
Solution of my problem:
It works for me with pondering what exactly happen in the process of connection.Hope my thinking will lead u to kill ur error.
When I experienced this error in Visual Studio,
...it was during the execution of the following C# code, which was attempting to obtain my SQL Server data to display it in a grid. The break occurred exactly on the line that says connect.Open():
It was inexplicable because the SQL query was very simple, I had the right connection string, and the database server was available. I decided to run the actual SQL query manually myself in SQL Management Studio and it ran just fine and yielded several records. But one thing stood out in the query results: there was some improperly encoded HTML text inside a varchar(max) type field within the Friends table (specifically, some encoded comment symbols of the sort
<!--
lodged within the "Narrative" column's data). The suspect data row looked like this:Notice the encoded HTML symbol "
<
", which stood for a "<" character. Somehow that made its way into the database and my C# code could not pick it up! It failed everytime right at the connect.Open() line! After I manually edited that one row of data in the database table Friends and put in the decoded "<" character instead, everything worked! Here's what that row should have looked like:I edited the one bad row I had by using this simple UPDATE statement below. But if you had several offending rows of encoded HTML, you might need a more elaborate UPDATE statement that uses the REPLACE function:
So, the moral of the story is (at least in my case), sanitize your HTML content before storing it in the database and you won't get this cryptic SQL Server error in the first place! (Uh, properly sanitizing/decoding your HTML content is the subject of another discussion worthy of a separate StackOverflow search if you need more information!)
I resolved this problem by setting the project that makes use of Entity Framework as the start-up project and then run the "update-database" command.