Results 1 to 9 of 9

Thread: [RESOLVED] Access to vs "Add Connection form

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Location
    Portland, OR, USA
    Posts
    659

    Resolved [RESOLVED] Access to vs "Add Connection form

    Hi All.

    Not sure which forum this was best for (Database developement or vb.Net). If you think it belongs in the Database Development forum, please move it.

    I am wondering if it is possible to conjure up vs "Add Connection" form from when attempting to log in from a vb.net client application. Normally, we build our app's so that the connection kind of happens behind the scenes. In this case, I want the user to be able to select a server, and log the app in using one of the pre-fab forms mentioned above. .

    I am working on some basic code generation stuff, which requires the user to be able to specify a database at run-time. While I could (and have) create my own log-in form, it seems like the familiar vs "add connection" form might be better suited (and easier) to use in this context.

    Any thoughts?

    btw, I have tried digging something up on this, and can't find the right way to search (WAY too many returns for "log-in" related searches).

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Access to vs "Add Connection form

    That dialogue is part of the VS application, not part of the .NET Framework, so you wouldn't be licensed to use it anyway. You'd have to create your own form that reproduced the same functionality.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Location
    Portland, OR, USA
    Posts
    659

    Re: Access to vs "Add Connection form

    I figured, but I also figured I had better ask before I gave up. The break between the Framework and items proprietary to vs is not always clear to me . . .

    I have gone down many dead-end roads as I learn this stuff, only later to find I had taken the really, REALLY long way around (although I often end up learning some valuable stuff this way, even though it doesn't apply to the CURRENT project).

    I just did it again, too, and should have known better. I made a bunch of custom functionality to retreive some very specific database info from sql server. Created a bunch of garbage in my app to insert certain sprocs, check for the existence of certain database items, column properties and what not.

    THEN I remembered SMO.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access to vs "Add Connection form

    A method I have used before (in VB6, so the code isn't apt) is to let Windows do the work - by creating an empty file (or pre-filled from template) with a .udl extension, and ShellExecute'ing it.

    Windows then shows a dialog to set the connection properties, and saves the connection string to the file.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Location
    Portland, OR, USA
    Posts
    659

    Re: Access to vs "Add Connection form

    HA!

    I will have to check that out.


    If you had a sample of vb6 code, I would be interested in seeing it (I am semi-fluent that way), as Shell Executing is but a vague concept to me.

    But I am also going to search the forum and msdn for shell execute . . .


    I think I also recall seeing some sort of Shell Execute method in the smo library somewhere.

    Thanks!

    I'm not marking this "resolved" yet, until I get home and check it out. I may have more questions . . .!~

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Access to vs "Add Connection form

    That would be Process.Start in VB.NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access to vs "Add Connection form

    I've just checked my code, and it seems that it isn't ideal - I've written a routine called 'ShellExecuteAndWait' (which waits until the dialog closes), but the code doesn't seem to be up to par, and my notes tell me it hasn't been tested as thoroughly as it should be.

    Due to that (and it being wrong for .Net), it is probably best if I don't post it - at least not unless you can't get a .Net version working properly.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Access to vs "Add Connection form

    Here's some code that does what si is suggesting.
    Code:
    Dim tempFilePath = Path.GetTempFileName()
    Dim udlFilePath = Path.ChangeExtension(tempFilePath, ".udl")
    
    File.Move(tempFilePath, udlFilePath)
    
    Using proc = Process.Start(udlFilePath)
        proc.WaitForExit()
    End Using
    
    Dim lines = File.ReadAllLines(udlFilePath)
    
    File.Delete(udlFilePath)
    
    If lines.Length > 0 Then
        MessageBox.Show(lines(lines.GetUpperBound(0)))
    End If
    Just note that it won't let you create a connection string for SqlClient; only OleDb. You could always use connection string builders to transfer the property values and create a SqlClient connection string if you wanted, but it seems a little bit dodgy to me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Location
    Portland, OR, USA
    Posts
    659

    Re: Access to vs "Add Connection form

    @jmchilhinney: Thanks for that! I'm gonna see how dodgy it gets, and may just revert back to the custom form I created.

    @si_the_geek: I'm going to mess with this as well.

    @all:

    I had already created a log-in form which handled retreiving connection info for SQL Server. My HOPE was that there was something available which duplicated the multi-function of the vs "add connection" form, or if not, would cause whatever the normal log-in form mechanism specific to a particular RBDMS to pop-up on demand.

    Actually, I find it odd that there ISN'T some mechanism for this. It seems like the ubiquitous "they" either allow for direct connection via code, or logging in through the front of the DB management tool (ala SQL Server Management Studio), but no way to cause the DB to request log-in info when an attempt to log in is made.

    While it isn't SUPER challenging to create such a thing as part of an app, it also seems like such a basic function that it would be available as a pre-fab tool, either on the DB vendor end, or from within .NET.

    Thanks to both for the input!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width