supersal666
Member
Hi people, I have created a console app which is supposed to backup a database. I wanted to use SQLDMO as alot of the examples are in this but get an error when running my code like below:
COMException was unhandled
Retrieving the COM class factory for component with CLSID {10021F00-E260-11CF-AE68-00AA004A34D5} failed due to the following error: 80040154.
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147221164
Message="Retrieving the COM class factory for component with CLSID {10021F00-E260-11CF-AE68-00AA004A34D5} failed due to the following error: 80040154."
Source="SQLNightlyBackup"
StackTrace:
at SQLNightlyBackup.Module1.Main() in C:\Users\sally\AppData\Local\Temporary Projects\SQLNightlyBackup\Module1.vb:line 9
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
i basically just downloaded the interop.SQLDMO.dll to my machine then added it as a reference from the references tab. I'm using sql server express 2008 and vb 2008 express edition. Is this the correct way to do it and does anyone know why i am getting the error?
Here is my code although it crashes on the first line
Any help would be gratefully recieved!
Thanks
Sally
COMException was unhandled
Retrieving the COM class factory for component with CLSID {10021F00-E260-11CF-AE68-00AA004A34D5} failed due to the following error: 80040154.
System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147221164
Message="Retrieving the COM class factory for component with CLSID {10021F00-E260-11CF-AE68-00AA004A34D5} failed due to the following error: 80040154."
Source="SQLNightlyBackup"
StackTrace:
at SQLNightlyBackup.Module1.Main() in C:\Users\sally\AppData\Local\Temporary Projects\SQLNightlyBackup\Module1.vb:line 9
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
i basically just downloaded the interop.SQLDMO.dll to my machine then added it as a reference from the references tab. I'm using sql server express 2008 and vb 2008 express edition. Is this the correct way to do it and does anyone know why i am getting the error?
Here is my code although it crashes on the first line
VB.NET:
Imports Microsoft.SqlServer
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.IO
Module Module1
Sub Main()
Dim backup As SQLDMO.Backup = New SQLDMO.BackupClass() ' crashes here
Dim sqlserver As SQLDMO.SQLServer = New SQLDMO.SQLServerClass()
sqlserver.LoginSecure = False
sqlserver.Connect("sql.ima-group.co.uk", "sa", "password")
backup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
backup.Database = "CrackerDrinks"
backup.Files = "C:\SQLBackups\National\TestDataBase.bak"
backup.BackupSetName = "Test01"
backup.BackupSetDescription = "Database backup description"
backup.Initialize = True
backup.SQLBackup(sqlserver)
End Sub
End Module
Any help would be gratefully recieved!
Thanks
Sally