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.