user3432257
user3432257

Reputation: 415

what is the connection string for this database

I have a database called MyDatabase exists in sql server 2008 r2 on windows server 2003

I want to test my website on that server using Windows Authentication

My Question

what is the connection string

I think that

connectionString="Initial Catalog=MyDatabase;Data Source=localhost;Integrated Security=SSPI;"/>

But I don't know if it is correct. Also, I can't try because I have to give the code to my manager, I need to be everything perfect when I gave them.

i am using .net framework 4

Upvotes: 0

Views: 1675

Answers (1)

Milica Medic Kiralj
Milica Medic Kiralj

Reputation: 3750

You can check that by going to Tools->Connect to Database

enter image description here

In the Add Connection dialog you'll have your server name and your db name (or add it) and click the Advanced button

enter image description here

In the Advanced Properties dialog copy the string marked below:

enter image description here

This will be your string, in this case:

SqlConnection con = new SqlConnection("DataSource=MCA\\LENOVO;Initial  Catalog=DecryptTesting;Integrated Security=True");

Make sure you add one more slash "\" like above or an "@" to a connection. You need to escape the backward slash \ in your connection string or use the "@" symbol if you want to avoid escaping characters in your string:

SqlConnection con = new SqlConnection(@"DataSource=MCA\LENOVO;Initial Catalog=DecryptTesting;Integrated Security=True");

EDIT: DataSource is the name of your server, Initial Catalog is your database

Hope this helps

Upvotes: 3

Related Questions