473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB .Net (VisualStudio 2005) and the SQL Server SMO Object question

I was told to post this in one of the dotnet groups. I hope this is the
correct one.
Several months ago, I took the official Microsoft 2733B course to upgrade my
skills from SQL 2000 to SQL 2005 and one of the neat things the course did
was show us how to create an SMO object which backs up a database at the
click of a button. Now that we're finally moving to SQL Server 2005 at work,
I went to whip up this little program following the instructions at work, but
I'm having a problem.

When I create this project from scratch, it gives me the error: Name
"DatabaseList" is not declared. This is really strange as when I pull up the
sample solution from the CD we got, everything is almost exact the same,
including the IMPORTS. Can someone help me figure out what I'm missing that
VS thinks "DatabaseList" is a variable instead of a real object? Form is
simple, 1 textbox and 1 button. Code is listed below:
'##### Add imports statements here #####
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common

Public Class DBBackupForm

'##### Add variable declarations here”
Dim myServer As New Server()
Dim conn As ServerConnection
Private Sub BackupDatabaseButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BackupDatabaseButton.Click
' If no database is selected, exit this event handler
If DatabaseList.SelectedIndex = -1 Then Exit Sub

'##### Add backup code here #####
Dim dbName As String = DatabaseList.SelectedItem.ToString
Dim MyBackup As New Backup
Dim ProcessDate As Date
ProcessDate = Now()
Dim BackupTime As String
BackupTime = ProcessDate.ToString("YYYY") &
ProcessDate.ToString("MM") _
& ProcessDate.ToString("DD") & ProcessDate.ToString("HH") _
& ProcessDate.ToString("MM")

MyBackup.Action = BackupActionType.Database
MyBackup.BackupSetName = dbName & "Backup"
MyBackup.Database = dbName
Dim MyDevice As BackupDeviceItem = New BackupDeviceItem( _
"\\MyServerName\SQL_BAK\" & dbName & BackupTime & ".BAK",
DeviceType.File)

MyBackup.Devices.Add(MyDevice)

MyBackup.SqlBackup(myServer)

MessageBox.Show(dbName & " backed up in the SQL_BAK folder with the
following FileName: " _
& CStr("\\MyServerName\SQL_BAK\" & dbName & BackupTime & ".BAK"))
End Sub

Private Sub DatabaseListTextBox_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DatabaseListTextBox.TextChanged

'##### Add connection code here #####
conn = myServer.ConnectionContext
conn.ServerInstance = "localhost"
conn.Connect()

'##### Add list database code here #####
Dim db As Database
For Each db In myServer.Databases
DatabaseList.Items.Add(db.Name)
Next

End Sub
End Class

------------------------------

Thanks for any help anyone can give me.

Catadmin
--
MCDBA, MCSA
Random Thoughts: If a person is Microsoft Certified, does that mean that
Microsoft pays the bills for the funny white jackets that tie in the back???
@=)
Aug 29 '06 #1
1 1670
Hello Catadmin,

That's what ya get for copy n pastin stuff without understanding it.

First, you say there is only one textbox and one button on your form. Fine..
then what is DatabaseList?? I see you trying to mess with DatabaseList.SelectedIndex..
Neither the textbox nor the button have this property.. a combobox does
(as do other list-based controls). Next, I see a TextChanged event handler
for something called DatabaseListTextBox.. which I assume is the afore mentioned
textbox.

My guess is you make your UI with a button and a textbox.. did a lil copy
paste action because yer too damn lazy to be bothered doing something right..
got the name of the control wrong.. and in fact got the control type wrong..
and now yer pissin and moanin to us, wasting our time. Quit bein a lazy
bastard.

-Boo
I was told to post this in one of the dotnet groups. I hope this is
the correct one.

Several months ago, I took the official Microsoft 2733B course to
upgrade my skills from SQL 2000 to SQL 2005 and one of the neat things
the course did was show us how to create an SMO object which backs up
a database at the click of a button. Now that we're finally moving to
SQL Server 2005 at work, I went to whip up this little program
following the instructions at work, but I'm having a problem.

When I create this project from scratch, it gives me the error: Name
"DatabaseList" is not declared. This is really strange as when I pull
up the sample solution from the CD we got, everything is almost exact
the same, including the IMPORTS. Can someone help me figure out what
I'm missing that VS thinks "DatabaseList" is a variable instead of a
real object? Form is simple, 1 textbox and 1 button. Code is listed
below:

'##### Add imports statements here #####
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Public Class DBBackupForm

'##### Add variable declarations here”
Dim myServer As New Server()
Dim conn As ServerConnection
Private Sub BackupDatabaseButton_Click(ByVal sender As
System.Object,
ByVal e As System.EventArgs) Handles BackupDatabaseButton.Click
' If no database is selected, exit this event handler
If DatabaseList.SelectedIndex = -1 Then Exit Sub
'##### Add backup code here #####
Dim dbName As String = DatabaseList.SelectedItem.ToString
Dim MyBackup As New Backup
Dim ProcessDate As Date
ProcessDate = Now()
Dim BackupTime As String
BackupTime = ProcessDate.ToString("YYYY") &
ProcessDate.ToString("MM") _
& ProcessDate.ToString("DD") & ProcessDate.ToString("HH") _
& ProcessDate.ToString("MM")
MyBackup.Action = BackupActionType.Database
MyBackup.BackupSetName = dbName & "Backup"
MyBackup.Database = dbName
Dim MyDevice As BackupDeviceItem = New BackupDeviceItem( _
"\\MyServerName\SQL_BAK\" & dbName & BackupTime & ".BAK",
DeviceType.File)
MyBackup.Devices.Add(MyDevice)

MyBackup.SqlBackup(myServer)

MessageBox.Show(dbName & " backed up in the SQL_BAK folder
with the
following FileName: " _
& CStr("\\MyServerName\SQL_BAK\" & dbName & BackupTime &
".BAK"))
End Sub
Private Sub DatabaseListTextBox_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DatabaseListTextBox.TextChanged

'##### Add connection code here #####
conn = myServer.ConnectionContext
conn.ServerInstance = "localhost"
conn.Connect()
'##### Add list database code here #####
Dim db As Database
For Each db In myServer.Databases
DatabaseList.Items.Add(db.Name)
Next
End Sub
End Class
------------------------------

Thanks for any help anyone can give me.

Catadmin

Aug 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maziar Aflatoun | last post by:
Hi everyone, I'm relatively new to VisualStudio 2003 and have to create an application that uses Web Services to authenticate a user. Once that user is authenticated I use the Web services...
5
by: John H Clark | last post by:
I am building an IHttpHandlerFactory to process all requests to folders in my site. When an attempt to access internal folders is detected the request is rerouted to an error page. All other...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.