为什么我的代码在“con.Open()”之后停止?

发布于 2024-08-15 23:30:03 字数 571 浏览 2 评论 0原文

在我的代码中,为什么在 con.Open() 之后不执行任何操作。
如果我单步执行每个步骤,它会在 con.Open() 之后结束 Form1_Load 事件。

Imports System.Data.OleDb

Public Class Form1

Dim con As OleDbConnection
Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\testDB.accdb"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    con = New OleDbConnection(strCon)

    con.Open()
    MsgBox("con open")

    con.Close()
    MsgBox("con closed")

End Sub
End Class

In my code, why does nothing execute after con.Open().
If I step through each step, it ends the Form1_Load event after con.Open().

Imports System.Data.OleDb

Public Class Form1

Dim con As OleDbConnection
Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\testDB.accdb"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    con = New OleDbConnection(strCon)

    con.Open()
    MsgBox("con open")

    con.Close()
    MsgBox("con closed")

End Sub
End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如梦初醒的夏天 2024-08-22 23:30:03

听起来好像开始引发错误。

您是否尝试过使用 OnError Goto Handler 类型代码来构建代码?请参阅错误声明

如果这是 VB.NET,请尝试使用 Try ... Catch 捕获异常。然后在 Catch 语句上设置断点以找出错误所在。

Sounds like an Error is begin raised.

Have you tried framing your code with OnError Goto Handler type code? See the On Error Statement.

If this is VB.NET, trying catching an exception with Try ... Catch. Then set a breakpoint on the Catch statements to find out what the error is.

伤痕我心 2024-08-22 23:30:03

安装MS Access数据库引擎(使用Microsoft.ACE.OLEDB.12.0)后,我的程序仍然无法运行。我仍然有错误:

“‘Microsoft.ACE.OLEDB.12.0’提供程序未在本地 muoeachine 上注册。”

我还必须更改高级编译配置,因为我在 Windows 7 64 位上运行,并且可能“...将处理器类型锁定为 32 位”。

如何更改设置:

1.工具->选项。
2.勾选“显示所有设置”。
3.在左侧的树视图中,选择“项目和解决方案”。
4.在右侧的选项中,选中“显示高级构建配置”框。
5.单击“确定”。
6.转到构建->配置管理器...
7.在“平台”列的下拉列表中选择“新建”。
8. 在第一个下拉框中选择“x86”。
9.“好的”

更多信息:Microsoft.ACE.OLEDB.12.0 提供程序未注册

After installing the MS Access Database Engine (to use Microsoft.ACE.OLEDB.12.0), my program still did not work. I still had the error:

"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local muoteachine."

I also had to change the advanced compile configuration because I am running on Windows 7 64 bit and may have "...locked the processor type to 32-bit".

How to change the settings:

1.Tools -> Options.
2.Check "Show all settings".
3.In the tree-view on the left hand side, select "Projects and Solutions".
4.In the options on the right, check the box that says, "Show advanced build configuraions."
5.Click OK.
6.Go to Build -> Configuration Manager...
7.In the Platform column select "new" in the drop down list.
8. Select "x86" under first dropdown box.
9. "Ok"

More info here: Microsoft.ACE.OLEDB.12.0 provider is not registered

贪恋 2024-08-22 23:30:03

即使您有适当的 try catch 块,有时 con.Open() 也会花费几秒钟的时间来抛出异常,因为它正在等待服务器。跟随错误需要一段时间才能引发异常,并且看起来好像您的单步执行消失了。要有耐心!

“ORA-12170:TNS:发生连接超时”

Even if you have proper try catch block some time it take several seconds for the con.Open() to throw an exception since it's waiting for the server. Following error takes a while to throw an exception and it will appear as if your Step Into disappeared. Be patient!

"ORA-12170: TNS:Connect timeout occurred"

╭⌒浅淡时光〆 2024-08-22 23:30:03

导入 System.Data.Odbc

公共类 Form11

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim a1, a2, a6, a3, a4, a5, a7 As String
    ' Dim a2, a6 As Integer
    a1 = txtname.Text
    a3 = txtaddress.Text
    a4 = txtcity.Text
    a5 = txtmail.Text
    a7 = txtbalance.Text
    a2 = txtmob.Text
    a6 = txtvehicles.Text
    Dim con As New OdbcConnection("DSN = crusher_schema")
    con.Open()
    MsgBox("Databse Connected", MsgBoxStyle.Information, "add")
    Dim cmd As New Odbc.OdbcCommand("insert into customer values('" & a1 & "','" & a2 & "','" & a3 & "','" & a4 & "','" & a5 & "','" & a6 & "','" & a7 & "', con")
    Dim r As Integer
    r = cmd.ExecuteNonQuery
    If r = 1 Then
        MessageBox.Show("Succesfully inserted" & r)
    Else
        MessageBox.Show("Not inserted" & r)
    End If!

Form.vb

Imports System.Data.Odbc

Public Class Form11

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim a1, a2, a6, a3, a4, a5, a7 As String
    ' Dim a2, a6 As Integer
    a1 = txtname.Text
    a3 = txtaddress.Text
    a4 = txtcity.Text
    a5 = txtmail.Text
    a7 = txtbalance.Text
    a2 = txtmob.Text
    a6 = txtvehicles.Text
    Dim con As New OdbcConnection("DSN = crusher_schema")
    con.Open()
    MsgBox("Databse Connected", MsgBoxStyle.Information, "add")
    Dim cmd As New Odbc.OdbcCommand("insert into customer values('" & a1 & "','" & a2 & "','" & a3 & "','" & a4 & "','" & a5 & "','" & a6 & "','" & a7 & "', con")
    Dim r As Integer
    r = cmd.ExecuteNonQuery
    If r = 1 Then
        MessageBox.Show("Succesfully inserted" & r)
    Else
        MessageBox.Show("Not inserted" & r)
    End If!

Form.vb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文