Visual Studio connects connectionStringz and visualstudiosql of SQL Server.

Source: Internet
Author: User

Visual Studio connects connectionStringz and visualstudiosql of SQL Server.

Recently, the course design of C # and data structure has used C # to connect to the SQL Server database, which involves the problem of attaching and connecting database files.

The most annoying issue is the connection String problem in SqlConnection (String connStr.

Here we can find a simple method without writing the connection command by yourself.

First, connect your database files through.

Click Tools in the navigation bar> connect to the database

I used windows Authentication here. If you download SQL Server Manager Studio and have the relevant username and password, you can use SQL Server for verification.

Here you can select a data source. If you select MicroSoft SQL Server, connect to a database. The first choice or input a database requires that you have used SQL Server to attach the database file to the Server, first, move the database file to the place where SQL Server stores the database. Right-click the database in SQL Server Manager Studio and choose attach.


The second option is to directly append your database files.


There are also many ways to connect to the database. Baidu is not the focus of my speech.

I want to talk about a connection character connecting to the database when the code is running after the connection is successful.

SqlConnection myConn = new SqlConnection (@ "Data Source =. \ SQLEXPRESS; Initial Catalog = storage_Data.MDF; Integrated Security = True ;");

The content in this double quotation mark sometimes fails to connect to the database because of different database connection methods.

Note that the @ mentioned above cancels the meaning of the escape characters in double quotation marks, so that you do not need to escape the characters when writing the path in it.

How can I quickly know how to fill in the connection command here?

Right-click the connected database on the left. Choose modify connection> advanced. Do you see a string of Data Soure in the bottom line?


Copy. Paste OK




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.