Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to have User Input set ServerConnection object 1

Status
Not open for further replies.

Catadmin

Programmer
Oct 26, 2001
3,097
US
I'm probably searching under the wrong things, because I can't find this one and I'm sure someone else has already asked this. If someone could point, I'd greatly appreciate it.

I'm using a SQL Management Object to backup databases on various SQL Servers. It's being coded via Visual Studio 2005 in VB .Net. Rather than recreate the program for every SQL Server we have, I'd like to open it up to user Input. Is there a way to do a Console.Readline() and pass it on to a ServerConnection object?

Or... is there a way to populate a list of currently available Servers so the user can just pick one?

I don't want to hard code the servers in because I'll be sharing this program with other departments who have their own servers and I don't want them messing with the guts of the program. Essentially, I'm thinking of a popup box a lot like the RemoteDesktop connection box where it keeps in memory your last few choices and allows you to enter a new one.

My current module is something like:

Code:
Module CreateInitialConnection
    Public ProdServer As New Server()
    Public ProdConn As ServerConnection
    'Public MyServer As String

    Public Sub CreateMyConnection()
        'System.Console.Write("Enter your Server name and port number (if applicable) as <MyServer>, <port>: ")
       ' MyServer = System.Console.ReadLine()
        ProdConn = ProdServer.ConnectionContext
        ProdConn.ServerInstance = "<MyServer>, <MyPort>"

        'If MyServer.ToString() = Nothing Then
        '    MsgBox("You must enter a proper SQL Server name to continue")
       ' Else
          '  ProdConn.ServerInstance = MyServer.ToString()
        'End If


    End Sub
End Module

The commented out lines are where I tried to set it up to read a user String and failed miserably. I keep getting a NULLReferenenceException (Object reference not set to an instance of an object.) error.

As always, help is greatly appreciated. Even if you just point me to a few links.

Thanks,



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
It looks like you're asking how to serialise this data so that it can be held outside the application.

You could try XML or hold the data in a database.

faq796-6320 - Rick's recent posting for an XML based INI file substitute shows how to read and write to xml files.

For this sort of thing where you have a list of servers that is fairly static, but will be different from department to department you might want to consider holding this in a central location on the network that all users have access to or in a database. Either of these approaches will make it easier to maintain the list.

Alternatively, you might want to look at faq796-6142. This faq shows you how to get a list of all available SQL Servers in vs2005

Hope this helps
 
Thank you for the links. The second FAQ was exactly what I was looking for, though the other information is extremely helpful also.

Star for your assist! It's greatly appreciated.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Techsmith,

I've got another question you might be able to answer, related to this issue.

Following the tips in the second FAQ (using the SMO.Application.EnumAvailableSqlServers), is there a way, once the end user has picked a server, that the application can retain the user's choice for later? Like the way the Remote Desktop Connection keeps a short list of servers for you to down-arrow and choose from. Or the most recent URLs in Internet Explorer. Even though you close both programs, when you open them up again, some settings are retained.

If anyone else can answer this question, I'd be greatly appreciative. Thanks,





Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
If you are asking how to retain the server name that the user last selected, then you need some sort of 'user preference' type solution such as holding the setting against a user record in a database or holding user preferences in an xml file in the "C:\Documents and Settings\..UserName..\Application Data\..YourApp.." folder.

The main thing is to store the information somewhere that will always be accessible to the user regardless of the machine they are working on.

I prefer to record this kind of info in the database against a users record, but then I'm a DBA so that's my comfort zone.
 
Techsmith,

Thank you so very very much for your assistance. I greatly appreciate it. You've been incredibly helpful.

For the record, I'm a DBA myself, so I agree with you on the database thing. Now I just need to figure out a good setup for it.

Thanks again!



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top