Visual Studio connects SQL Server's Connectionstringz and

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.