运行vb.net应用程序以连接到本地数据库时出现System.Runtime.InteropServices.COMException

时间:2018-08-23 15:44:16

标签: vb.net adodb comexception

如果在调试文件夹中运行.exe,我当前的应用程序可以在Visual Studio中的调试模式下完美运行。当我切换到发布模式或尝试打包要安装的应用程序时,启动时始终会失败。

我已设置断点,而我的失败点似乎是此函数(代码的最后一行),当它试图打开与本地DB的连接以通过登录屏幕进行处理时。在加载登录屏幕时,我确实有一个查询要呼叫信息。

Public Shared Function Open(ByVal SQL As String) As ADODB.Recordset
    common.LogSQL(SQL)
    Dim tempRS As ADODB.Recordset
    tempRS = New ADODB.Recordset
    tempRS.CursorLocation = 3 'use client
    tempRS.CursorType = 3 'static
    tempRS.LockType = 3 'optimistic
    tempRS.Open(SQL, AccMdbConn)
    Open = tempRS
End Function

Visual Studio中的错误:

System.Runtime.InteropServices.COMException: 'The connection cannot be used to perform this operation. It is either closed or invalid in this context.'

堆栈错误为:

8/23/2018 9:04:22 AM - The connection cannot be used to perform this operation. It is either closed or invalid in this context.
   at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)
   at TestEntry.accmdb.Open(String SQL) in C:\Users\Test\Developer\Visual Studio Projects\Updater\TestEntry\accmdb.vb:line 83
   at TestEntry.frmLogin.frmLogin_Load(Object sender, EventArgs e) in C:\Users\Test\Developer\Visual Studio Projects\Updater\TestEntry\frmLogin.vb:line 23
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

当我尝试在另一台计算机上安装时,我确切地收到此错误。我的意思是完全相同的路径在所有计算机的堆栈中显示。我的代码中没有任何硬编码的路径。

有人对我为导致此问题所做的事情有任何想法吗?

0 个答案:

没有答案