|
-
May 24th, 2025, 11:49 AM
#1
Thread Starter
Hyperactive Member
I found this module and have 3 instances and I do not know how to call the module.
Hi guys, I'm asking for help with a module that module supposed to backup data from SQL and later restore it to the same location.
Thank you to all of you guys, blessings.
I found this module, which I had to modify for my application, but I stopped when I tried to call the module. I tried in three different ways, and I can't get it to run.
I know the simple module, but this one is more difficult. I would appreciate it if one of you could help me.
Code:
Module Program
Sub Main()
Dim connectionString As String = "Server = localhost \ SQLEXPRESS;Database=master;Trusted_Connection=True;"
Dim databaseName As String = "citas"
Dim backupFilePath As String = "C:\CitasBackRes\To\BackupFile.bak"
Dim dbManager As New DatabaseBackupRestore()
' Backup the database
dbManager.BackupDatabase(connectionString, databaseName, backupFilePath)
' Restore the database
dbManager.RestoreDatabase(connectionString, databaseName, backupFilePath)
End Sub
End Module
Module MainModule
Private BackupDatabase As Object
Sub Program()
' Call the subroutine without specifying the namespace
BackupDatabase.dbmanager()
End Sub
End Module
Last edited by Shaggy Hiker; May 24th, 2025 at 10:13 PM.
Reason: Added CODE tags.
mannyso
-
May 24th, 2025, 04:20 PM
#2
Re: I found this module and have 3 instances and I do not know how to call the module
but I stopped when I tried to call the module. I tried in three different ways, and I can't get it to run.
What does that even mean?? You don't call a Module, you call the procedures/functions within a module. Plus, you posted two modules so we have no idea which one your talking about.
btw - When posting code, use code tags, click the "#" and paste the code. That we maintain the code formatting and make it much easier to read.
-
May 24th, 2025, 10:16 PM
#3
Re: I found this module and have 3 instances and I do not know how to call the module
While I have never done a SQL backup through code, this method could be in a module, or could be somewhere else. It's what you want. I'm not sure what the second module even gets you:
Code:
Sub Main()
Dim connectionString As String = "Server = localhost \ SQLEXPRESS;Database=master;Trusted_Connection=True;"
Dim databaseName As String = "citas"
Dim backupFilePath As String = "C:\CitasBackRes\To\BackupFile.bak"
Dim dbManager As New DatabaseBackupRestore()
' Backup the database
dbManager.BackupDatabase(connectionString, databaseName, backupFilePath)
' Restore the database
dbManager.RestoreDatabase(connectionString, databaseName, backupFilePath)
End Sub
The thing is, though, that you don't want that method called Main(). Main is a special function, as it's the entry point into a program. If you want to do the backup within some other program, rename the method to something else.
That second module is doing some goofy late binding thing. Perhaps late binding does have some purpose here, but that whole second module doesn't seem worthwhile, let alone using late binding.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|