【发布时间】:2012-01-10 19:33:27
【问题描述】:
我搜索了很多,没有找到任何有用的东西,所以我在这里。
我用 C#(任何 CPU 设置)编写了一个应用程序,该应用程序已经在 Windows 7 和 XP x86 上运行了一段时间,没有出现错误。
最近我的办公室已将我的工作站升级到 Windows 7 x64(从 x86)。
当我在 Visual Studio 2010 中运行我的应用程序时,我在运行或编译时没有收到任何错误。它按设计工作。
我的 VS2010 版本是我们 MSDN 订阅的 10.0.30319.1 RTMRel,框架是 4.0.30319 RTMRel
当我直接运行已编译的应用程序时,我在使用 SqlConnection 对象时收到错误消息。无论我选择任何 CPU 还是 x86 都会发生相同的错误。
在我的类文件中,这是例程:
public static SqlConnection getDBConnection()
{
SqlConnection sqlConn = null;
try
{
sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["KpH2Oprod"].ConnectionString);
sqlConn.Open();
}
catch
{
throw;
}
finally
{
if (sqlConn == null)
{
sqlConn.Dispose();
}
}
return sqlConn;
}
一些手动跟踪我发现错误不是在SqlConnection sqlConn = null; 第一次实例化时而是在我实际设置它时抛出的:
sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["KpH2Oprod"].ConnectionString);
我已将此行更改为:
sqlConn = new SqlConnection();
sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["KpH2Oprod"].ConnectionString;
查看它是 SqlConnection 还是配置管理器,它确实在 sqlConn = new SqlConnection(); 行上抛出。事实上,这是我开始的方式并将其更改为以前的方式,无论如何,在使用新指令时都会抛出错误。
我得到的实际错误消息是(其中一些是我自己的消息):
我相信这可能与 SQL 对象的注册方式有关,但消息在前几行的中心被截断(不是我做的),指向参数 g 为空。这再次完美地在调试器中工作。
RunTimeError :
Value cannot be null.
Parameter name: g
at System.Guid..ctor(String g)
at kpH2O.frmMain..ctor() (mscorlib)
ACTION :
UPDATEINCIDENT ()
PROGRESS :
WORKING ()
RunTimeError :
Object reference not set to an instance of an object.
at kpH2O.db.getDBConnection()
at kpH2O.db.getIncidentIDFromNumber(String incidentNumber)
at kpH2O.frmMain.updateHeatIncident() (kpH2O)
ERROR :
Process UPDATEINCIDENT: FAILED (doStartUp)
这是一个开箱即用的 VS2010 安装,没有任何插件。非常感谢任何帮助。
【问题讨论】:
-
有没有办法只捕获原始异常/堆栈跟踪?
-
另外 - 拥有一个只包含 throw 语句的 catch 子句没有任何好处。
-
@DJKRAZE:连接字符串无关紧要,因为他甚至在设置连接字符串属性之前就得到了异常。
标签: c# database x86 64-bit sqlconnection