簡體   English   中英

將SQL連接從ASP Classic轉換為ASP.NET

[英]Convert SQL connection from Asp classic to asp.net

我想將我的網頁從Asp classic轉換為Asp.net(VB),我應該怎么做才能代替此代碼?

conn.asp的:

<%
    Dim conn,connstr
        connstr = "Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345"
        on error resume next
        set conn=server.createobject("ADODB.CONNECTION")
        conn.open connstr
            if err then
                err.clear
                set conn=nothing
                response.write "Connect Error!"
                response.End         
            End IF

    %>

感謝您的時間!

在C#中

using (SqlConnection connection = new SqlConnection("Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345"))
{
    connection.Open();
    // Do work here; connection closed on following line.
}

VB.NET

Using connection As New SqlConnection("Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345")
    connection.Open()
    // Do work here; connection closed on following line. 
End Using 

各種連接字符串可以在這里找到

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM