带有Mono SQL Server故障的C#窗体

本文关键字:窗体 故障 Server Mono SQL 带有 | 更新日期: 2023-09-27 17:59:10

我是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

我用这篇文章作为模型: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);
    }
}

我相信这比构建你的应用程序并在Mono中运行更复杂,所以如果有人能引导我朝着正确的方向前进,我真的很感激。谢谢。

带有Mono SQL Server故障的C#窗体

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