473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ 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
"DatabaseLi st" 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 "DatabaseLi st" 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.SqlSe rver.Management .Smo
Imports Microsoft.SqlSe rver.Management .Common

Public Class DBBackupForm

'##### Add variable declarations here”
Dim myServer As New Server()
Dim conn As ServerConnectio n
Private Sub BackupDatabaseB utton_Click(ByV al sender As System.Object,
ByVal e As System.EventArg s) Handles BackupDatabaseB utton.Click
' If no database is selected, exit this event handler
If DatabaseList.Se lectedIndex = -1 Then Exit Sub

'##### Add backup code here #####
Dim dbName As String = DatabaseList.Se lectedItem.ToSt ring
Dim MyBackup As New Backup
Dim ProcessDate As Date
ProcessDate = Now()
Dim BackupTime As String
BackupTime = ProcessDate.ToS tring("YYYY") &
ProcessDate.ToS tring("MM") _
& ProcessDate.ToS tring("DD") & ProcessDate.ToS tring("HH") _
& ProcessDate.ToS tring("MM")

MyBackup.Action = BackupActionTyp e.Database
MyBackup.Backup SetName = dbName & "Backup"
MyBackup.Databa se = dbName
Dim MyDevice As BackupDeviceIte m = New BackupDeviceIte m( _
"\\MyServerName \SQL_BAK\" & dbName & BackupTime & ".BAK",
DeviceType.File )

MyBackup.Device s.Add(MyDevice)

MyBackup.SqlBac kup(myServer)

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

Private Sub DatabaseListTex tBox_TextChange d(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
DatabaseListTex tBox.TextChange d

'##### Add connection code here #####
conn = myServer.Connec tionContext
conn.ServerInst ance = "localhost"
conn.Connect()

'##### Add list database code here #####
Dim db As Database
For Each db In myServer.Databa ses
DatabaseList.It ems.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 1685
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.Se lectedIndex..
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 DatabaseListTex tBox.. 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
"DatabaseLi st" 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 "DatabaseLi st" 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.SqlSe rver.Management .Smo
Imports Microsoft.SqlSe rver.Management .Common
Public Class DBBackupForm

'##### Add variable declarations here”
Dim myServer As New Server()
Dim conn As ServerConnectio n
Private Sub BackupDatabaseB utton_Click(ByV al sender As
System.Object,
ByVal e As System.EventArg s) Handles BackupDatabaseB utton.Click
' If no database is selected, exit this event handler
If DatabaseList.Se lectedIndex = -1 Then Exit Sub
'##### Add backup code here #####
Dim dbName As String = DatabaseList.Se lectedItem.ToSt ring
Dim MyBackup As New Backup
Dim ProcessDate As Date
ProcessDate = Now()
Dim BackupTime As String
BackupTime = ProcessDate.ToS tring("YYYY") &
ProcessDate.ToS tring("MM") _
& ProcessDate.ToS tring("DD") & ProcessDate.ToS tring("HH") _
& ProcessDate.ToS tring("MM")
MyBackup.Action = BackupActionTyp e.Database
MyBackup.Backup SetName = dbName & "Backup"
MyBackup.Databa se = dbName
Dim MyDevice As BackupDeviceIte m = New BackupDeviceIte m( _
"\\MyServerName \SQL_BAK\" & dbName & BackupTime & ".BAK",
DeviceType.File )
MyBackup.Device s.Add(MyDevice)

MyBackup.SqlBac kup(myServer)

MessageBox.Show (dbName & " backed up in the SQL_BAK folder
with the
following FileName: " _
& CStr("\\MyServe rName\SQL_BAK\" & dbName & BackupTime &
".BAK"))
End Sub
Private Sub DatabaseListTex tBox_TextChange d(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
DatabaseListTex tBox.TextChange d

'##### Add connection code here #####
conn = myServer.Connec tionContext
conn.ServerInst ance = "localhost"
conn.Connect()
'##### Add list database code here #####
Dim db As Database
For Each db In myServer.Databa ses
DatabaseList.It ems.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
1010
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 object and store it in a session to use it in the following pages. However, every time I stop VisualStudio to modify my code and start it again I have to start the whole process all over again and it becomes really time consuming. Is there an easier...
5
1387
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 attempts are processed using return PageParser.GetCompiledPageInstance(url, pathTranslated, context);
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.