简体   繁体   中英

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

图片

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM