我的场景是,我在开发机器上创建了一个VB.NET应用程序,现在希望使用包和部署向导将其分发到另一台机器。
开发机器上的代码运行良好
,但当我在目标计算机上安装它时,它会给出一个null引用异常。
我在目标机器上有一个访问数据库,它是我在开发机器上使用的数据库的精确副本。我的连接字符串是在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消息、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
杜拉小工具
程序集版本: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
系统.核心
程序集版本: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
系统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
系统运行时.情绪化
程序集版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.30319-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.30319-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.30319-0100)
代码库:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
命名空间
程序集版本: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)调试
应用程序或计算机(machine.config)必须具有
jit在system.windows.forms部分中设置的调试值。
应用程序也必须通过调试进行编译
启用。
例如:
启用JIT调试时,任何未处理的异常
将发送到计算机上注册的JIT调试器
而不是由该对话框处理。