runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Unable to load DLL 'sni.dll'

Open sravan1022 opened this issue 10 years ago • 6 comments

I have seen several threads and applied all the solutions but unable to resolve my issue. I am building a simple console application which uses SQL Client for connecting to a database and execute the query in VS 2015 and i am getting this error. I installed visual c++ also for VS 2015 but it didn't solve my issue. What else i can do to resolve this ? P.S I am using .NET core 1.0.0. version

sravan1022 avatar May 25 '16 05:05 sravan1022

@sravan1022 can you provide the stack trace? Can I also see your project.json?

saurabh500 avatar May 25 '16 19:05 saurabh500

@saurabh500 I just thought that it may be missing the sni.dll so i copied it to the bin folder of the project and the error changed to "An attempt was made to load a program with incorrect format". Is it because i am using windows 7 ? Now the stack trace is empty.

My project.json is : { "version": "1.0.0-*", "description": "sqlClientExample console Appplication",

"buildOptions": { "emitEntryPoint": true, "defines": [ ] },

"dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0-rc2-3002702" }, "System.Runtime": "4.1.0-rc2-24027", "System.Data.Common": "4.0.1-rc2-24027", "System.Data.SqlClient": "4.0.0-beta-23123", "System.Data.SqlClient.sni-x86": "4.0.0-beta-23123" },

"frameworks": { "netcoreapp1.0": { "imports": "dnxcore50" } } }

sravan1022 avatar May 26 '16 05:05 sravan1022

@saurabh500 I tried the same code using windows 10 and guess what, it worked perfectly. Now the connection is successful. So with windows 7, 32-bit sni.dll "The error is An attempt was made to load a program with incorrect format" whereas with 64-bit sni.dll "The error is Unable to load sni.dll". Now with windows 10,32-bit sni.dll "The error is An attempt was made to load a program with incorrect format" and with 64-bit it worked perfectly. Hope this will be useful for someone.

sravan1022 avatar May 26 '16 12:05 sravan1022

Reopening. This issue needs verification on windows 7

saurabh500 avatar May 31 '16 16:05 saurabh500

@sravan1022 I looked into the issue and I couldnt repro this on a new Win7 installation. Can you try to change the SqlClient version to "4.1.0-rc2-24027"

My project.json from the modified hello world donet cli app has

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "System.Data.SqlClient" : "4.1.0-rc2-24027"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

The program.cs

using System;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource = "Hostname";
                builder.UserID = "username";
                builder.Password = "MyPass";
                builder.InitialCatalog = "TestDataBase";
                builder.MinPoolSize = 50;
                builder.Pooling = true;
                builder.MaxPoolSize = 200;

        SqlConnection conn = new SqlConnection(builder.ConnectionString);
        conn.Open();
        conn.Close();
        }
    }
}


saurabh500 avatar Jun 01 '16 01:06 saurabh500

@saurabh500 I tried my previous program by changing SqlClient version to "4.1.0-rc2-24027" but the error is same with more warnings.

I even tried your program but there is an sql exception hnadler error.Check it once.

sravan1022 avatar Jun 07 '16 06:06 sravan1022