Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. open UDL Dialog at runtime

open UDL Dialog at runtime

Scheduled Pinned Locked Moved Database
csharpquestionworkspace
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Itanium
    wrote on last edited by
    #1

    Hi All, When we double click a .udl file it opens the configuration dialog for connectionstring. What if i would like to open this dialog box at runtime using C# or VB.net? Thanx in advance. sorry for my bad English.

    M Richard DeemingR 2 Replies Last reply
    0
    • I Itanium

      Hi All, When we double click a .udl file it opens the configuration dialog for connectionstring. What if i would like to open this dialog box at runtime using C# or VB.net? Thanx in advance. sorry for my bad English.

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      Write click on your .udl file and choose OPEN WITH--->CHOOSE PROGRAM and then choose VS.NET to open it. Mazy No sig. available now.

      I 1 Reply Last reply
      0
      • M Mazdak

        Write click on your .udl file and choose OPEN WITH--->CHOOSE PROGRAM and then choose VS.NET to open it. Mazy No sig. available now.

        I Offline
        I Offline
        Itanium
        wrote on last edited by
        #3

        Hi, Infact i wana say that i would like to openthe UDL dialog on soem event e.g OnButton_Click eent i would like to Open this dialog and retrieve the connection string. Can u provide some clue. Thanx in Advance:) sorry for my bad English.

        M 1 Reply Last reply
        0
        • I Itanium

          Hi, Infact i wana say that i would like to openthe UDL dialog on soem event e.g OnButton_Click eent i would like to Open this dialog and retrieve the connection string. Can u provide some clue. Thanx in Advance:) sorry for my bad English.

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          I think this will work:

          Process.Start("path to VS.NET","path to your .udl file");

          But I'm not exactly sure ,maybe you need to pass file path in first argument too. Mazy No sig. available now.

          H 1 Reply Last reply
          0
          • M Mazdak

            I think this will work:

            Process.Start("path to VS.NET","path to your .udl file");

            But I'm not exactly sure ,maybe you need to pass file path in first argument too. Mazy No sig. available now.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            Actually, he just wants to open the file with its associated program / shell handler, so the following should be used:

            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "path/to/file.udl";
            psi.UseShellExecute = true;
            Process.Start(psi);

            ShellExecute(Ex) is what is executed when you double-click a file (or do whatever is the default action based on shell settings). You can also pass different verbs, like "open", "edit", "print", etc., so long as they are supported by the file type association in the registry.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            1 Reply Last reply
            0
            • I Itanium

              Hi All, When we double click a .udl file it opens the configuration dialog for connectionstring. What if i would like to open this dialog box at runtime using C# or VB.net? Thanx in advance. sorry for my bad English.

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Take a look at: HOW TO: Build a Connection String Programmatically in ADO.NET by Using Visual C# .NET[^] For a more reusable sample, try this code:

              using System;
              using System.ComponentModel;
              using System.Runtime.InteropServices;
              using System.Windows.Forms;
              using ADODB;
              using MSDASC;

              public sealed class DataLinkDialog : CommonDialog
              {
              private string _connectionString;

              /// <summary>
              /// Constructor
              /// </summary>
              /// <param name="connectionString">The initial connection string</param>
              public DataLinkDialog(string connectionString)
              {
                  \_connectionString = connectionString;
              }
              
              /// <summary>
              /// Constructor
              /// </summary>
              public DataLinkDialog()
              {
                  \_connectionString = string.Empty;
              }
              
              /// <summary>
              /// Gets or sets the connection string
              /// </summary>
              public string ConnectionString
              {
                  get { return \_connectionString; }
                  set { \_connectionString = value; }
              }
              
              /// <summary>
              /// Resets the properties of the dialog box
              /// to their default values.
              /// </summary>
              public override void Reset()
              {
                  \_connectionString = string.Empty;
              }
              
              /// <summary>
              /// Displays the dialog box.
              /// </summary>
              /// <param name="hwndOwner">
              /// A value that represents the window handle of the 
              /// owner window for the common dialog box.
              /// </param>
              /// <returns>
              /// true if the dialog box was successfully run;
              /// otherwise, false.
              /// </returns>
              protected override bool RunDialog(IntPtr hwndOwner)
              {
                  DataLinks dl = new DataLinksClass();
                  try
                  {
                      if (null == \_connectionString || 0 == \_connectionString.Length)
                      {
                          object ret = dl.PromptNew();
                          if (null == ret)
                          {
                              return false;
                          }
                          else
                          {
                              \_connectionString = ((ADODB.\_Connection)ret).ConnectionString;
                              Marshal.ReleaseComObject(ret);
                              return true;
                          }
                      }
                      else
                      {
                          Connection cn = new Connecti
              

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups