Reputation: 140
I develop a Windows Forms Application on a 32 bit Win7 machine and have a SQL Server 2008 on the same machine for testing. The database server of the release inviroment has 64 bit. When I install the application on a client (32 bit) in the release inviroment which is connected with the 64 bit SQL Server I get the following failure when my code try to use SQL Server Management Objects (SMO):
Code which causes the failure:
private static bool createDatabase(string dbName, string sqlPath, string connStr)
{
FileInfo file = new FileInfo(sqlPath + dbName + ".sql");
string strscript = file.OpenText().ReadToEnd();
bool result;
string test = "CREATE DATABASE [" + dbName + "]";
try
{
SqlConnection connection = new SqlConnection(connStr);
using (connection)
{
using (SqlCommand sqlCmd = new SqlCommand(test, connection))
{
connection.Open();
sqlCmd.ExecuteNonQuery();
connection.Close();
result = true;
}
}
if (result == true)
{
connStr = connStr + ";Initial Catalog=" + dbName;
SqlConnection sqlConnection = new SqlConnection(connStr);
ServerConnection svrConnection = new ServerConnection(sqlConnection);
Server server = new Server(svrConnection);
server.ConnectionContext.ExecuteNonQuery(strscript); // Here the app crashes
}
}
catch (SqlException ae)
{
result = false;
System.Windows.Forms.MessageBox.Show(ae.Message.ToString());
}
return result;
}
Failure message:
Anwendung: XingaAdmin.exe Frameworkversion: v4.0.30319 Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet. Ausnahmeinformationen: System.IO.FileNotFoundException Stapel: bei System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean, Boolean) bei System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean, Boolean) bei System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean, Boolean) bei System.Reflection.RuntimeAssembly.InternalLoad(System.String, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean) bei System.Reflection.Assembly.Load(System.String) bei Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(System.String, Microsoft.SqlServer.Management.Common.ExecutionTypes, Int32 ByRef) bei Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(System.String, Microsoft.SqlServer.Management.Common.ExecutionTypes) bei XingaCommonClasses.Utilities.Database.DatabaseHelper.createDatabase(System.String, System.String, System.String) bei XingaCommonClasses.Utilities.Database.DatabaseHelper.checkDatabase(System.Collections.Generic.List`1, System.String) bei XingaAdmin.Program.Main()
The database is created fine, but the sql-script with the table creation is not executed.
Is it possible that I have to use the 64 bit version of the SQL Server Management Objects (SMO)? But if, how can I get this version. I cannot install the 64 bit version on a 32 bit machine.
Upvotes: 1
Views: 1825
Reputation: 37225
This question contains the same stack trace, but the stack dump also contains information about which SMO assembly failed to load. Use a try-catch block to dump the stack trace in the exception.
The SQL Server machine needs to have the 64bit SMO library installed.
Upvotes: 1