Reputation:
I have created a database and a simple web form with couple of text-filled and a submit button in visual studio 2019(Asp.net c#). now I'm trying to save user data into the tables, since I'm not using sql server management do I still need use SqlConnection if so what is the best way to create a connecting string?
Upvotes: 1
Views: 195
Reputation: 2603
The best way to create a connection string is to write it in the Web.Config file which you will find it at the bottom of your Project in Solution Explorer.
Web.config file is basically an xml file that contains the configuration of your websites which includes your connection string.
<connectionStrings>
<add name="YourConnectionStringNameHere" connectionString="Data Source= DatabaseServerName; Integrated Security=true;Initial Catalog= YourDatabaseName; uid=YourUsernamehere; Password=Yourpasswordhere; " providerName="System.Data.SqlClient" />
</connectionStrings>
Why to write the connection string in Web.config?
The SQL connection would still be required:
The SQLConnection would be required in order to connect to the database no matter whether you use SSMS or not. Even in the internal database that Visual Studio provides, you will be required to provide this connection string reference in your .cs file.
Hope this helps.
Upvotes: 2