简体   繁体   中英

C# Winforms with Mono SQL Server Failure

I'm new to Mono, and I'm trying to do some very basic proof-of-concept testing for running a winforms app with Mono. I built a very simple app in VS2012 (has basically one button and some data access code), and ran it through MoMA, and everything checks out. But, when I try running my .exe with Mono (using the Mono-2.10.9 command prompt), I get the following error in the error log:

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

I was using this article as a model: http://www.mono-project.com/Guide:_Porting_Winforms_Applications . It seems to indicate that you can write and build in VS2012 using C#, and simply run using Mono, but obviously that's not true for the data code. Here's the method causing the exception:

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);
    }
}

I'm sure it's more complicated than just building your app and running it in Mono, so if somebody could steer me in the right direction, I'd really appreciate it. Thanks.

I got things working now, without any changes to the code listed! I had several other SQL access methods defined in a class, and it must've been one of them causing the error. Not sure why a method I wasn't calling would cause an exception, but that's what was happening, and the exception just didn't provide any guidance. Thanks for offers to help, anyway. And sorry for unjustly accusing you, Mono.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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