0

我已经设法使用 sqlexpress 使用 localhost 连接到数据库,所以我的连接字符串是正确的,但是我托管在 123-reg 上,无法连接到我在他们的服务器上创建的数据库。我尝试了 SQL 插入和选择语句,以查看在我的网站上实时查看时我的网站是否可以连接到它,但它没有连接。是连接失败,我不确定我是否正确链接到服务器。

123-reg 给了我一个连接字符串以插入我的 webconfig 页面:

<add key="ConnectionString" value="*****; Database=*****; User Id=*****; Password=*****" />

我尝试使用以下方法在 aspx 页面上访问它:

    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Try
        con.ConnectionString = "Provider=*****;DataSource=*****; Initial Catalog=*****; User Id=*****; Password=*****;"

        con.Open()
        cmd.Connection = con
        cmd.CommandText = "insert into test (note) values ('works')"
        cmd.ExecuteNonQuery()


    Catch ex As Exception
        MsgBox("Error while inserting record on table..." & ex.Message)
    Finally
        con.Close()
        Label1.Text = "works"
    End Try
4

1 回答 1

0

他们给你:Provider SqlOleDb

这意味着您应该使用 OleDb 类(OleDbConnection, OleDbCommand等)而不是 SqlClient 命名空间中的类(SqlConnection, SqlCommand等)。

如果这是真的,并且他们没有提供更新的 Sql Native Client 的替代方案,我认为您必须更改代码以使用这些类(或更改提供程序)

于 2013-05-21T20:50:54.590 回答