C#Winforms与Mono SQL Server故障

C#Winforms与Mono SQL Server故障,c#,winforms,sql-server-2008,mono,C#,Winforms,Sql Server 2008,Mono,我是Mono新手,我正在尝试用Mono运行winforms应用程序的一些非常基本的概念验证测试。我在VS2012中构建了一个非常简单的应用程序(基本上只有一个按钮和一些数据访问代码),并通过MoMA运行了它,一切都正常。但是,当我尝试使用Mono运行我的.exe(使用Mono-2.10.9命令提示符)时,在错误日志中出现以下错误: Unhandled Exception: System.NullReferenceException: Object reference not set to an

我是Mono新手,我正在尝试用Mono运行winforms应用程序的一些非常基本的概念验证测试。我在VS2012中构建了一个非常简单的应用程序(基本上只有一个按钮和一些数据访问代码),并通过MoMA运行了它,一切都正常。但是,当我尝试使用Mono运行我的.exe(使用Mono-2.10.9命令提示符)时,在错误日志中出现以下错误:

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

我相信这比构建应用程序并在Mono中运行要复杂得多,所以如果有人能指引我正确的方向,我会非常感激。谢谢。

我现在可以工作了,没有对列出的代码做任何更改!我在一个类中定义了其他几个SQL访问方法,它一定是其中一个导致错误的方法。我不确定为什么我没有调用的方法会导致异常,但这就是发生的情况,异常只是没有提供任何指导。无论如何,谢谢你的帮助。很抱歉不公正地指责你,Mono。

对此毫无把握,所以这只是一个评论,但看起来你的GetConnectionString()调用可能返回了
null
。你的
SqlConnection
字符串定义在哪里?Monkey想知道你是否定义了SQLCommandTimeout应用程序设置?@JoelCoehoorn--no,我知道它不会返回
null
,因为它本机运行良好,我可以在调试中逐步完成它,它就在那里@Brian——我的连接字符串位于配置中的
appSetting
中。Mono不支持
ConfigurationManager.ConnectionString
集合,因此我将连接字符串放在
appSettings
中。Mono在应用设置方面有问题吗?@JeffBorden——告诉Monkey我有问题,但谢谢你的提问。
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);
    }
}