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. General Programming
  3. C#
  4. How to use Universal Link Data (C#)?

How to use Universal Link Data (C#)?

Scheduled Pinned Locked Moved C#
csharpdatabasehelptutorialquestion
5 Posts 3 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.
  • M Offline
    M Offline
    Miri Ofir
    wrote on last edited by
    #1

    Hallo I try to write a window application that connect to database with udl. The connection is O.k (I tested it), but when I want to use it in my code, it failed. my code: static SqlConnection con = new SqlConnection(); con.ConnectionString = "File Name=C:\\WINNT\\myConnection.udl;"; con.Open(); I also tried: con.ConnectionString = @"File Name=C:\WINNT\PrePaidDb.udl;"; and also try to define it in app.setting. the error is always: {"Keyword not supported: 'file name'." } Do someone has any idea. Thanks a lot

    N 1 Reply Last reply
    0
    • M Miri Ofir

      Hallo I try to write a window application that connect to database with udl. The connection is O.k (I tested it), but when I want to use it in my code, it failed. my code: static SqlConnection con = new SqlConnection(); con.ConnectionString = "File Name=C:\\WINNT\\myConnection.udl;"; con.Open(); I also tried: con.ConnectionString = @"File Name=C:\WINNT\PrePaidDb.udl;"; and also try to define it in app.setting. the error is always: {"Keyword not supported: 'file name'." } Do someone has any idea. Thanks a lot

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      The SqlConnection class doesn't support the File Name connection string parameter, thus it would fail. You can do this with the OleDbConnection class however:

      OleDbConnection conn = new OleDbConnection(@"File Name = c:\test.udl");
      try
      {
      conn.Open();
      if(conn.State == ConnectionState.Open)
      {
      MessageBox.Show("Connection successful.");
      }
      }
      catch(Exception ex)
      {
      MessageBox.Show(ex.Message);
      }
      finally
      {
      conn.Close();
      }

      - Nick Parker
      My Blog | My Articles

      M 1 Reply Last reply
      0
      • N Nick Parker

        The SqlConnection class doesn't support the File Name connection string parameter, thus it would fail. You can do this with the OleDbConnection class however:

        OleDbConnection conn = new OleDbConnection(@"File Name = c:\test.udl");
        try
        {
        conn.Open();
        if(conn.State == ConnectionState.Open)
        {
        MessageBox.Show("Connection successful.");
        }
        }
        catch(Exception ex)
        {
        MessageBox.Show(ex.Message);
        }
        finally
        {
        conn.Close();
        }

        - Nick Parker
        My Blog | My Articles

        M Offline
        M Offline
        Miri Ofir
        wrote on last edited by
        #3

        Thank you Nick. The DB is in SqlServer and not in Access, is that means that I couldn't use udl to create connection?

        A 1 Reply Last reply
        0
        • M Miri Ofir

          Thank you Nick. The DB is in SqlServer and not in Access, is that means that I couldn't use udl to create connection?

          A Offline
          A Offline
          Alex Korchemniy
          wrote on last edited by
          #4

          I believe you can use OleDBConnection for SQL also but its not optimized. Why dont you just store the connection in the config file?? :confused: This posting is provided "AS IS" with no warranties, and confers no rights. Alex Korchemniy

          M 1 Reply Last reply
          0
          • A Alex Korchemniy

            I believe you can use OleDBConnection for SQL also but its not optimized. Why dont you just store the connection in the config file?? :confused: This posting is provided "AS IS" with no warranties, and confers no rights. Alex Korchemniy

            M Offline
            M Offline
            Miri Ofir
            wrote on last edited by
            #5

            Thank you everybody. Finally I found a way to do what I want. I read the connectionString as a text file.:-O using (StreamReader sr = new StreamReader("c://WINNT//myConnection.udl")) { string line; //--the connection string is define at the third line of the file line = sr.ReadLine(); line = sr.ReadLine(); line = sr.ReadLine(); connectionString = line; }

            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