Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi In my project i use SMO and threads for generating script from a data base and create a new database(in sql server 2008),then transfer tables,...(except data)in to the new one.
I write the code below,so this error appear in line which create a server connection.

the error :

Could not load file or assembly 'Microsoft.SqlServer.SqlClrProvider, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

this is the mycode:

C#
Thread th = new Thread(new ThreadStart(CreatDB));
th.Start();
public void CreatDB()
{
try
{


SqlConnection con2;
conString2 = " Data Source=MC040;Initial Catalog= CurrentDataBaseName;Integrated Security=SSPI";
con2 = new SqlConnection(conString2);

ServerConnection conn = new ServerConnection(con2);
Server srv = new Server(conn);

Transfer trsfrDB = new       Transfer(srv.Databases[CurrentDataBaseName]);
Microsoft.SqlServer.Management.Smo.Database newDatbase = new Microsoft.SqlServer.Management.Smo.Database(srv, "NewDBName");
newDatbase.Create();
ScriptingOptions options = new ScriptingOptions();
options.DriAll = true;
options.ClusteredIndexes = true;
options.Default = true;
options.Indexes = true;
trsfrDB.Options = options;
trsfrDB.CopyAllObjects = true;
trsfrDB.CopyAllViews = true;
trsfrDB.CopyAllUsers = true;
trsfrDB.CopyAllDefaults = true;
trsfrDB.CopyAllDatabaseTriggers = true;
trsfrDB.CopyAllUserDefinedTableTypes = true;
trsfrDB.CopyAllSchemas = true;
//Copy all user defined data types from source to destination
trsfrDB.CopyAllUserDefinedDataTypes = true;
//Copy all tables from source to destination
trsfrDB.CopyAllTables = true;
//Copy data of all source tables to destination tables
//It actually generates INSERT statement for destination
//trsfrDB.CopyData = true;
//Copy all stored procedure from source to destination
trsfrDB.CopyAllStoredProcedures = true;
//specify the destination server name
trsfrDB.DestinationServer = srv.Name;
trsfrDB.DestinationLoginSecure = false;
trsfrDB.DestinationLogin = "UserName";
trsfrDB.DestinationPassword = "Password";
trsfrDB.DestinationDatabase = "NewDBName";
trsfrDB.TransferData();

}
catch (System.Exception ex)
{
}
}


please tell me how can i fix this problem.Its so important for me.
Posted
Updated 26-Oct-14 1:41am
v2

I solve it my self.
All the assemblies file that add to my project should have been in the same version.My code get error because 2 of them were in version 11,however the other were in 10.
The assebly files which are compatible with your sql server of you windows, are here:
C:\Program Files\Microsoft Sql Server\100\SDK\Assemblies.
 
Share this answer
 
v2
Comments
King Fisher 29-Oct-14 8:14am    
Good Job. :) mark it as Answer .so it will be move out from unanswered QA Queue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900