C#Winforms与单声道SQL服务器故障
问题描述:
我是新来的单声道,我试图做一些非常基本的概念验证测试运行与Mono的Winforms应用程序。我在VS2012中构建了一个非常简单的应用程序(基本上有一个按钮和一些数据访问代码),并通过MoMA运行它,并检查所有内容。但是,当我尝试运行我的.exe和Mono(使用单2.10.9命令提示符),我得到以下错误在错误日志中:C#Winforms与单声道SQL服务器故障
Unhandled Exception: System.NullReferenceException: Object reference not set to an
instance of an object
at Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection() [0x00000] in <filename
unknown>:0
at System.Data.SqlClient.SqlConnection.Open() [0x00000] in <filename unknown>:0
at MonoWinForm1.DataAccess.ExecuteSQLSelect (ConnectionStrings connectionString,
System.String sql) [0x00000] in <filename unknown>:0
at MonoWinForm1.Form1..ctor() [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) MonoWinForm1.Form1:.ctor()
at MonoWinForm1.Program.Main() [0x00000] in <filename unknown>:0
我用这篇文章作为模型:http://www.mono-project.com/Guide:_Porting_Winforms_Applications 。这似乎表明,您可以使用C#编写和构建VS2012,并且只需使用Mono即可运行,但显然这对于数据代码并非如此。下面是导致异常的方法:
DataSet results = new DataSet();
using (SqlConnection connection = new SqlConnection(GetConnectionString(connectionString)))
{
using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
command.CommandType = CommandType.Text;
command.CommandTimeout = Int32.Parse(ConfigurationManager.AppSettings["SQLCommandTimeout"]);
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(results);
}
}
我敢肯定,它不仅仅是建立你的应用程序,并在单声道运行更加复杂,因此,如果有人能指导我在正确的方向,我会很感激。谢谢。
答
我现在正在工作,没有对列出的代码进行任何更改!我在类中定义了其他几种SQL访问方法,它一定是导致错误的其中一个。不知道为什么我没有调用的方法会导致异常,但这就是发生了什么,而例外只是没有提供任何指导。无论如何,感谢提供帮助。抱歉不公正地指责你,莫诺。
对此一无所知,所以它只是一个注释,但它看起来像您的GetConnectionString()调用可能会返回'null'。 – 2013-02-14 23:03:33
你的'SqlConnection'字符串在哪里定义? – Brian 2013-02-14 23:10:29
猴子想知道您是否定义了您的SQLCommandTimeout appSetting? – 2013-02-14 23:15:01