To generate a database connection string with VS2005

Source: Internet
Author: User
Tags config sql visual studio
Data | database | database Connection | String in Visual Studio 2005, we can visualize the generation of database connection strings, which are not recommended for manual coding in the actual procedure, unless you write a custom data access layer or business logic layer. The following are practical steps to implement a connection to SQL Server 2005.

1, drag a SqlDataSource control to the form page, as shown in the following figure.


2. Click on the smart tag at the top right of the SqlDataSource control, as shown in the following figure. and click the Configure Data source chain section.


3, after the "Configure Data Source" window, you will find in the window "connection string" area is empty, now we can click the "New Connection" button to generate a database connection string.


4. After the Add Connection window appears, we can select the data source as "Miscrosoft SQL Server". The server name can be set to the computer name, or it can be replaced with "localhost". Here we use Windows authentication to log on to the server and select "Northwind" as the database to be connected. Clicking the Test Connection button indicates that you are already able to connect to the appropriate data source if the prompt succeeds.


5. When you click the OK button, the Configure Data Source window appears with the following connection string:


6. In the window shown in the following illustration, you are prompted to save the connection to the application configuration file, and if you choose Yes, the connection string will be parsed with the new declarative expression syntax of ASP.net 2.0 and saved to the appropriate Web.config configuration file.


After you complete this configuration step, the resulting code is as follows:

Providername= "System.Data.SqlClient"/>

where name= "Northwind" is an "alias" to the connection string, the connection string can be parsed using <%$ connectionstrings:northwind%> syntax.

7. After completing the other steps, a Web.config configuration file will be automatically added to the Solution Explorer window. Save the appropriate configuration information for the program.




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.