繁体   English   中英

C#Winforms与Mono SQL Server失败

[英]C# Winforms with Mono SQL Server Failure

我是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中运行它要复杂得多,因此,如果有人可以引导我朝着正确的方向发展,我将不胜感激。 谢谢。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM