ASP.NET Tutorial/ Database/Connection Strings

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Add the connection string to a web configuration file higher in the folder hierarchy

   <source lang="csharp">

The root Web.Config file is located at the following path: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG</source>

Encrypting Connection Strings with aspnet_regiis located in C:\WINDOWS\Microsoft.NET\Framework\v27\

   <source lang="csharp">

aspnet_regiis -pef connectionStrings "c:\Websites\MyWebsite"</source>

Storing Connection Strings in the Web Configuration File

   <source lang="csharp">


   <add name="Products" 
        connectionString="Data Source=.\SQLEXPRESS;
        AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />

</configuration> You can add as many connection strings to the connectionStrings section as you want. <%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"


<html xmlns="" > <head id="Head1" runat="server">

   <title>Show Products</title>

</head> <body>

   <form id="form1" runat="server">
       Runat="server" />
       SelectCommand="SELECT * FROM Products"
       ConnectionString="<%$ ConnectionStrings:Products %>"
       Runat="server" />

</body> </html></source>