【发布时间】:2013-04-09 23:34:40
【问题描述】:
我的场景是我在我的开发机器上创建了一个 VB.NET 应用程序,现在希望使用打包和部署向导将它分发到另一台机器上。
开发机器上的代码完美运行,但是当我将它安装在目标机器上时,它给出了一个空引用异常。
我在目标机器上有一个访问数据库,它是我在我的开发机器上使用的数据库的精确副本。我的连接字符串在我的 app.config 文件中定义,我不知道如何继续。
这是我的 app.config 文件,其中包含我的连接字符串:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="connString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Dave\Documents\duraGadget.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>
这是我的 Form1 加载(根据错误消息出现空指针):
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
constring = ConfigurationManager.ConnectionStrings("connString").ConnectionString()
Dim sql As String = "SELECT * FROM duragadget ORDER BY skuNo ASC"
Dim connection As New OleDbConnection(constring)
Dim dataadapter As New OleDbDataAdapter(sql, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "dura")
connection.Close()
DataGridView1.DataSource = ds
DataGridView1.DataMember = "dura"
DataGridView1.Columns(1).Width = 125
DataGridView1.Columns(2).Width = 125
DataGridView1.Columns(3).Width = 125
DataGridView1.Columns(4).Width = 125
DataGridView1.Columns(5).Width = 5000
End Sub
这是目标机器上错误消息框对话框中显示的错误消息:
有关调用的详细信息,请参阅此消息的末尾 即时 (JIT) 调试,而不是此对话框。
*****异常文本** ***** System.NullReferenceException:对象引用未设置为对象的实例。 在 DuraGadget.Form1.Form1_Load(对象发送者,EventArgs e) 在 System.EventHandler.Invoke(对象发送者,EventArgs e) 在 System.Windows.Forms.Form.OnLoad(EventArgs e) 在 System.Windows.Forms.Form.OnCreateControl() 在 System.Windows.Forms.Control.CreateControl(布尔 fIgnoreVisible) 在 System.Windows.Forms.Control.CreateControl() 在 System.Windows.Forms.Control.WmShowWindow(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.ScrollableControl.WndProc(消息和 m) 在 System.Windows.Forms.Form.WmShowWindow(消息和 m) 在 System.Windows.Forms.Form.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
***** 加载的程序集** ***** mscorlib 程序集版本:4.0.0.0 Win32版本:4.0.30319.296 (RTMGDR.030319-2900)
代码库:file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
DuraGadget 程序集版本:1.0.0.0 Win32版本:1.0.0.0
代码库:file:///C:/Program%20Files/Default%20Company%20Name/DSN%20new%20Upgrade/DuraGadget.exe
Microsoft.VisualBasic 程序集版本:10.0.0.0 Win32版本:10.0.30319.1 构建者:RTMRel
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
系统 程序集版本:4.0.0.0 Win32版本:4.0.30319.1001 构建者:RTMGDR
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
System.Core 程序集版本:4.0.0.0 Win32版本:4.0.30319.1 构建者:RTMRel
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
System.Windows.Forms 程序集版本:4.0.0.0 Win32版本:4.0.30319.1002 构建者:RTMGDR
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
系统.绘图 程序集版本:4.0.0.0 Win32版本:4.0.30319.1001 构建者:RTMGDR
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
System.Runtime.Remoting 程序集版本:4.0.0.0 Win32版本:4.0.30319.1 (RTMRel.030319-0100)
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
系统.数据 程序集版本:4.0.0.0 Win32版本:4.0.30319.1 (RTMRel.030319-0100)
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
系统.配置 程序集版本:4.0.0.0 Win32版本:4.0.30319.1 (RTMRel.030319-0100)
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
System.Xml 程序集版本:4.0.0.0 Win32版本:4.0.30319.1 构建者:RTMRel
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
***** JIT 调试 ** ***** 要启用即时 (JIT) 调试,为此的 .config 文件 应用程序或计算机 (machine.config) 必须具有 在 system.windows.forms 部分设置的 jitDebugging 值。 应用程序还必须通过调试进行编译 已启用。
例如:
启用 JIT 调试后,任何未处理的异常 将发送到计算机上注册的 JIT 调试器 而不是被这个对话框处理。
【问题讨论】:
-
您确定无论您的应用程序在何处运行,您都可以访问用户文件夹吗?大多数情况下,用户文件夹被锁定为不可用,具体取决于您使用的 Windows 版本。
-
@kadumel 如何使安全性可用,以便可以访问所有安全性?目标机器使用XP
-
把你的数据库放到C:\,看看能不能打到。如果可以,那可能就是问题所在。如果仍然没有,那么还有另一个问题。如果是这种情况,那么您将需要编辑该文件夹的权限
标签: .net vb.net nullreferenceexception