Sql错误:无法加载文件或程序集'microsoft.sqlserver.sqlclrprovider,version = 13.100.0.0,culture = neutral,publickeytoken = 89845dcd8080cc91' [英] Sql error: could not load file or assembly 'microsoft.sqlserver.sqlclrprovider, version = 13.100.0.0, culture = neutral, publickeytoken=89845dcd8080cc91'
问题描述
美好的一天。
我收到此错误,我已尝试在论坛上建议的所有内容,但没有成功。
我的应用程序在保存时创建一个SQL连接文件单击按钮。这是我得到的错误:
无法加载文件或程序集'Microsoft.SqlServer.SqlClrProvider,Version = 13.100.0.0,Culture = neutral,PublickeyToken = 89845dcd8080cc91'或其依赖项之一。系统找不到指定的文件。
代码:
Good day.
I am getting this error, I've tried everything suggested on the forum whithout success.
My application creates an SQL connection file when the save button is clicked. This is the error I am getting:
Could not load file or Assembly 'Microsoft.SqlServer.SqlClrProvider, Version = 13.100.0.0, Culture = neutral, PublickeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
Code:
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (cmbServerName.Text == "")
{
MessageBox.Show("Please Select/Enter Server Name","SQL Server Settings", MessageBoxButtons.OK,MessageBoxIcon.Information);
cmbServerName.Focus();
return;
}
if (cmbAuthentication.SelectedIndex == 1)
{
if (txtUserName.Text == "")
{
MessageBox.Show("please enter user name", "SQL Server Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtUserName.Focus();
return;
}
if (txtPassword.Text == "")
{
MessageBox.Show("please enter password", "SQL Server Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtPassword.Focus();
return;
}
}
Cursor = Cursors.WaitCursor;
timer1.Enabled = true;
if (cmbAuthentication.SelectedIndex == 0)
{
con = new SqlConnection(@"Data source= '" + cmbServerName.Text.ToString() + "';Initial Catalog=master;Integrated Security=True;");
}
if (cmbAuthentication.SelectedIndex == 1)
{
con = new SqlConnection(@"Data Source= '" + cmbServerName.Text.ToString() + "';Initial Catalog=master;User ID= '" + txtUserName.Text.ToString() + "';Password='" + txtPassword.Text.ToString() + "'");
}
con.Open();
if ((con.State == ConnectionState.Open))
{
// MessageBox.Show("please enter password", "SQL Server Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (MessageBox.Show("It will create the Database and configure the sql server, Do you want to proceed?", "SQL Server Settings", MessageBoxButtons.YesNo , MessageBoxIcon.Information) == DialogResult.Yes)
{
using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\SQLSettings.dat"))
{
if (cmbAuthentication.SelectedIndex == 0)
{
sw.WriteLine(@"Data Source= '" + cmbServerName.Text.ToString() +"';Initial Catalog=DigitalCourtRollDB;Integrated Security=True");
sw.Close();
}
if (cmbAuthentication.SelectedIndex == 1)
{
sw.WriteLine(@"Data Source= '" + cmbServerName.Text.ToString() + "';Initial Catalog=DigitalCourtRollDB;User ID='" + txtUserName.Text.ToString()+"' ;Password= '" + txtPassword.Text.ToString() + "'");
sw.Close();
}
CreateDB();
}
}
else {
System.Environment.Exit(0);
}
}
MessageBox.Show("The Database has been created and SQL Server setting has been saved successfully..." + "\r\n" + "Application will be closed,Please start it again", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
System.Environment.Exit(0);
}
catch (Exception ex)
{
MessageBox.Show("Unable to connect to sql server" + "\r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if ((con.State == ConnectionState.Open))
{
con.Close();
}
}
}
void CreateDB()
{
try
{
con = new SqlConnection(@"Data source= '"+ cmbServerName.Text.ToString() + "';Initial Catalog=master;Integrated Security=True;");
con.Open();
string cb2 = "Select * from sysdatabases where name='DigitalCourtRollDB'";
cmd = new SqlCommand(cb2);
cmd.Connection = con;
rdr = cmd.ExecuteReader();
if (rdr.Read())
{
con = new SqlConnection(@"Data source='" + cmbServerName.Text.ToString() + "';Initial Catalog=master;Integrated Security=True;");
con.Open();
string cb1 = "Drop Database DigitalCourtRollDB";
cmd = new SqlCommand(cb1);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
con = new SqlConnection(@"Data source='" + cmbServerName.Text.ToString() + "';Initial Catalog=master;Integrated Security=True;");
con.Open();
string cb = "Create Database DigitalCourtRollDB";
cmd = new SqlCommand(cb);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
using (StreamReader sr = new StreamReader(Application.StartupPath + "\\DBScript.sql"))
{
st = sr.ReadToEnd();
Server server = new Server(new ServerConnection(con));
server.ConnectionContext.ExecuteNonQuery(st);
}
}
else {
con = new SqlConnection(@"Data source='" + cmbServerName.Text.ToString() + "';Initial Catalog=master;Integrated Security=True;");
con.Open();
string cb3 = "Create Database DigitalCourtRollDB";
cmd = new SqlCommand(cb3);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
using (StreamReader sr = new StreamReader(Application.StartupPath + "\\DBScript.sql"))
{
st = sr.ReadToEnd();
Server server = new Server(new ServerConnection(con));
server.ConnectionContext.ExecuteNonQuery(st);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if ((con.State == ConnectionState.Open))
{
con.Close();
}
}
}
以前是否有人遇到此问题?
我正在使用c#Visual Studio 2015. SQL server 2016.
非常感谢您提前。
我尝试了什么:
我尝试过不同的SQL实例版本,SQL 2016和2014。
我试图在不同的PC上运行代码,在虚拟机上仍然存在同样的问题
Has anybody experience this problem before?
I am using c# Visual Studio 2015. SQL server 2016.
Thank you very much in advance.
What I have tried:
I have tried on different SQL instance version, SQL 2016 and 2014.
I have tried to run the code on different PC, on virtual machine but still the same problem
推荐答案
请仔细阅读:。NET异常无法加载文件或程序集microsoft.sqlserver.sqlclrprovider 13.100.0.0安装SQL Server 2016之后| Microsoft Connect [ ^ ]
这篇关于Sql错误:无法加载文件或程序集'microsoft.sqlserver.sqlclrprovider,version = 13.100.0.0,culture = neutral,publickeytoken = 89845dcd8080cc91'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!