在将网站部署到主机提供程序时访问mdb数据库

时间:2017-02-04 04:18:14

标签: vb.net ms-access web

我将我的主机提供商从godaddy更改为webhosting世界,现在遇到了关于通过我的aspx页面的vb代码访问mdb数据库的问题。

以下是使用Microsoft可视化Web开发人员软件创建的代码。它在我的计算机上运行时以及部署到godaddy时运行良好。但是当我将它上传到虚拟主机世界时,它无法正常工作。

我联系了我的新主机提供商的支持团队,仍然无法解决问题。如果有人能够启发我,我将不胜感激....

Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page

    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        'test write
        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/number_database.mdb"))
        cn.Open()
        cmd = New OleDbCommand()
        cmd.Connection = cn
        cmd.CommandText = "INSERT INTO testing (a_name, a_id) VALUES (@a_name, @a_id)"
        cmd.Parameters.AddWithValue("@a_name", TextBox1.Text)
        cmd.Parameters.AddWithValue("@a_id", TextBox2.Text)


        cmd.ExecuteNonQuery()
        cn.Close()

        TextBox1.Text = ""
        TextBox2.Text = ""


        'test read
        Dim my_namelist(100), myid(100) As String
        Dim counter_read As Integer


        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/number_database.mdb"))
            cn.Open()
        cn.Open()
        cmd = New OleDbCommand("SELECT * FROM testing ", cn)

        Dim reader As OleDbDataReader
        reader = cmd.ExecuteReader()

        Do While reader.Read()
            my_namelist(counter_read) = reader.GetString(1)
            myid(counter_read) = reader.GetString(2)

            counter_read = counter_read + 1
        Loop
        reader.Close()

        TextBox3.Text = "database list" & vbNewLine & vbNewLine

        For a = 0 To counter_read
            TextBox3.Text = TextBox3.Text & my_namelist(a) & vbTab & vbTab & myid(a) & vbNewLine

        Next 

    End Sub

End Class

0 个答案:

没有答案