Visual Studio 2017 Connection String Cannot Connect to Server

I just installed Visual Studio 2017 Community. I am starting a new ASP.net WebForms C # project, but I have a problem with my connection string. Here's what I've done so far: Created a WebForms application with separate user accounts Changed the DefaultConnection setting in the web.config file to

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=s13.example.com;Initial Catalog=DB_9;User ID=DB_9_user;Password=myPwd;Integrated Security=False;"
  providerName="System.Data.SqlClient" />

      

Then I add the SqlDataSource and try to use the DefaultConnection, but I get the following error:

Failed to get the database schema for this connection. please make sure the connection settings are correct and that the database is online.
Failed to get data for this request.
Failed to connect to server (local).
Login failed for user "DB_9_user".

Then I checked that the server, username and password were correct. I used the same credentials in Sql Server Management Studio 2012 to successfully connect to the database. So, I picked up my old computer with Visual Studio 2013 Professional and recreated the project there. There were no problems changing the connection string and using it in the SqlDataSource control. Is there something else in VS 2017 Community Edition that is blocking my ability to connect to the database?

+3


source to share


4 answers


I don't have a complete solution, but I've noticed a couple of things that might help:



  • Failed to connect to server (local)

    This is not the server mentioned in the connection string. This means that it looks for a database server on your local workstation. Are you sure you are using the correct object or the correct string?

  • s13.example.com

    So scary because it looks like a public address. Are you trying to connect directly to the production host over the internet? This is not good. Typically, the database server is not directly accessible to the outside world. The webserver will be in the DMZ, where external users can go to the webserver, and the webserver can go to the DB server inside, but external users cannot directly connect to the DB server. For very small sites, they might be a machine, but these rules still have to be enforced by a firewall: no open access to the database. For development, you are working with a private copy of the database, not a website.

+1


source


Add the following to your connection string:

Persist Security Info=True;

      



This worked for me.

0


source


Here is my way of solving this problem. In Visual Studio, select Tools-> Connect to Database. Use the same credentials and server name as the connection string. Then, when you go to create your new data source, select SQL Database as the data source type. When you select your data connection, the connection you created earlier should be selectable instead of using the connection string. This will create a new connection string and add it to your web.config file. This should look exactly the same as the previous connection string. You can replace the old connection string with this one if you decide you are not updating anything using the old connection string.

0


source


use Persist Security Info=True;

in connection string. If you try to connect using Server Explorer or Object Explorer from the IDE, select the Save my password check box when adding a new database connection.

0


source







All Articles