The recent course design for C # and data structures has been used many times to connect SQL Server databases in C #, which involves additional and connectivity issues with database files.
The most annoying of these is SqlConnection (string connstr), which is a connection string problem.
Here you find a simple way to write a connection command without your own.
The first is to connect your database files via vs.
Connect to the database by clicking Tools, navigation Bar
I use Windows authentication here uniformly, and if you download SQL Server Manager Studio and have the associated user name password, you can use SQL Server authentication.
Here you can choose the data source, if you choose MicroSoft SQL Server, the following connection to a database, the first choice or enter a database if you have been SQL Server to attach the database file to the server, the practice is to first move the database files to SQL Where the server holds the database, right-click the SQL Server Manager Studio database to select Attach.
The second option is to attach your database files directly.
There are many ways to connect to the database, we Baidu, not what I want to say the focus.
What I'm saying is that after the connection succeeds, the code runs with a connection character to the database
SqlConnection myconn=new SqlConnection (@ "Data source=.\sqlexpress;initial catalog=storage_data.mdf;integrated Security=true; " );
The contents of this double quotation mark, sometimes because of different database connection mode, causes the connection database to fail.
Note that the @ above here is the meaning of canceling the escape character in double quotes, so you don't have to escape it when you write the path.
How do you know how to fill out the connection commands in the quickest way?
Right-click the connected database on the left. Choose Modify Connection, advanced, see the bottom line of data soure a string of characters?
Copy. Paste OK
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Visual Studio connects SQL Server's Connectionstringz and