我已经设法使用localhost使用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
答案 0 :(得分:0)
他们会给你:Provider SqlOleDb
,
这意味着您应该使用OleDb类(OleDbConnection, OleDbCommand
等)而不是SqlClient命名空间中的类(SqlConnection, SqlCommand
等)。
如果这是真的并且它们不提供更新的Sql Native Client的替代方案,我认为您必须更改您的代码以使用这些类(或更改提供程序)