在ASP中配置數(shù)據(jù)庫(kù)有幾種方法,具體取決于使用的數(shù)據(jù)庫(kù)類型和ASP版本。
示例(使用SQL Server):
<configuration>
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
然后在ASP代碼中使用連接字符串:
Dim connectionString As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
Dim con As New SqlConnection(connectionString)
示例(使用SQL Server):
Dim con As New SqlConnection("Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password")
示例(使用SqlDataSource):
<asp:SqlDataSource ID="MyDataSource" runat="server" ConnectionString="Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password" SelectCommand="SELECT * FROM MyTable"></asp:SqlDataSource>
這些方法可以根據(jù)實(shí)際需求和ASP版本進(jìn)行選擇和使用。