luca.p.alexandru
luca.p.alexandru

Reputation: 1750

C# SqlConnection ConnectionString

Could someone please help me in finding the correct SQL Connection String to connect to my database in C#. The database I wish to connect to is shown in the following screenshot from SQL Management Studio

image

Upvotes: 1

Views: 15428

Answers (3)

Termato
Termato

Reputation: 1610

You can store your connection strings in you web.config or app.config file. I have placed an example string in a snippett here:

<configure>
<connectionStrings>
<add name="YOURDESIREDCONNECTIONSTRINGNAME" connectionString="Data Source=IPADDRESSorURL;Initial Catalog=DATABASENAME;User ID=YOURUSERNAME;Password=YOURPASSWORD" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configure>

In your scenario, you are using SQL Express so use the following:

Data Source=.\SQLEXPRESS;

As far as you have described the question, this is the best answer I can give at the moment. I hope this helps and let me know if you have any questions.

Upvotes: 4

melodiouscode
melodiouscode

Reputation: 2069

The instance of SQL Server that you have highlighted is SQL Server Express which is either connected to using:

.\sqlexpress

or

SERVERNAME\sqlexpress

You can try:

Server=.\sqlexpress;Database=YOURDATABASENAME;User Id=YOURSQLUSERNAME;Password=YOURSQLUSERPASSWORD;

or

Server=.\sqlexpress;Database=YOURDATABASENAME;Trusted_Connection=True;

As others have said take a look at http://www.connectionstrings.com/sql-server/ for further reference on sql server connection strings.

Upvotes: 2

Ivan
Ivan

Reputation: 138

This site contains everything you need: http://www.connectionstrings.com/sql-server/. In your case server addres is .\sqlexpress or serverName\sqlexpress.

Upvotes: 0

Related Questions