为什么我的代码在“con.Open()”之后停止?
在我的代码中,为什么在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
听起来好像开始引发错误。
您是否尝试过使用
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 theCatch
statements to find out what the error is.安装MS Access数据库引擎(使用Microsoft.ACE.OLEDB.12.0)后,我的程序仍然无法运行。我仍然有错误:
我还必须更改高级编译配置,因为我在 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:
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
即使您有适当的 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"
导入 System.Data.Odbc
公共类 Form11
Form.vb
Imports System.Data.Odbc
Public Class Form11
Form.vb