I'm facing some problems with creating a connection string to my SQL Server database. I'm running Visual Studio 13. I want to connect to the database from a ASP.NET C# application. How should my connection string be formed?
-
6There are many only resources that will answer this question. A quick Google will give you many, many options. Do some research on the problem and I'm sure you will find the answer.Davin Tryon– Davin Tryon2015-01-31 22:33:05 +00:00Commented Jan 31, 2015 at 22:33
-
1possible duplicate of How to create a connection string in asp.net c#Nazmul Hossain– Nazmul Hossain2015-01-31 22:50:46 +00:00Commented Jan 31, 2015 at 22:50
Add a comment
|
3 Answers
If you have the database showing in the Server Exporer in Visual Studio you can copy the ConnectionString from it's properties.
However, Connection Strings aren't complicated, of course depending on your database settings, but the basic template looks like this:
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
There's a lot of references about Connection Strings out there, have a look.
Comments
The basic connectionString looks like-
If you are setting in Code behind file then do this -
string conStr = @"Data Source=ServerName;Initial Catalog=Database;User Id=User;Password=Password";
If want to set in Config file then follow this -
<appSettings>
<add key="KeyName" value="Data Source=ServerName;Initial Catalog=Database;User Id=User;Password=Password"/>
</appSettings>
Hope it helps..
1 Comment
Mohan Kamargiri
Thanks for editting and formatting it...I'll take care from next time..@mickl