【问题标题】:Convert SQL connection from Asp classic to asp.net将 SQL 连接从 Asp classic 转换为 asp.net
【发布时间】:2013-06-04 06:34:00
【问题描述】:

我想将我的网页从 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

    %>

感谢您的宝贵时间!

【问题讨论】:

    标签: asp.net sql-server sql-server-2008 asp-classic


    【解决方案1】:

    在 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 
    

    各种连接字符串都可以找到here

    【讨论】:

    • 我正在使用 VB.NET 我执行了您给我的代码,但它返回此错误:(编译器错误消息:BC30689:此语句不能出现在方法主体或 lambda 表达式多行之外)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多