Opening connection to db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Opening connection to db

    Hi

    I have the following connection info in my web.config file;

    <connectionStri ngs>
    <add
    providerName="S ystem.Data.SqlC lient" connectionStrin g="Data
    Source=MySQLSer ver.net;Initial Catalog=&quot;M yDB&quot;;Persi st Security
    Info=True;User ID=&quot;UID&qu ot;;Password=My Password" name="Events" />
    </connectionStrin gs>

    How can I open a connection to this db in my code?

    Thanks

    Regards


  • Iaml

    #2
    Re: Opening connection to db

    On May 31, 11:42 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
    Hi
    >
    I have the following connection info in my web.config file;
    >
    <connectionStri ngs>
    <add
    providerName="S ystem.Data.SqlC lient" connectionStrin g="Data
    Source=MySQLSer ver.net;Initial Catalog=&quot;M yDB&quot;;Persi st Security
    Info=True;User ID=&quot;UID&qu ot;;Password=My Password" name="Events" />
    </connectionStrin gs>
    >
    How can I open a connection to this db in my code?
    >
    Thanks
    >
    Regards
    This following article will help you:



    Comment

    • Peter Bromberg [C# MVP]

      #3
      Re: Opening connection to db

      SqlConnection conn = new
      SqlConnection(C onfigurationMan ager.Connection Strings["Events"].ConnectionStri ng);
      conn.Open();
      --Peter
      "John" <info@nospam.in fovis.co.ukwrot e in message
      news:uFD7Rm5wIH A.2208@TK2MSFTN GP04.phx.gbl...
      Hi
      >
      I have the following connection info in my web.config file;
      >
      <connectionStri ngs>
      <add
      providerName="S ystem.Data.SqlC lient" connectionStrin g="Data
      Source=MySQLSer ver.net;Initial Catalog=&quot;M yDB&quot;;Persi st Security
      Info=True;User ID=&quot;UID&qu ot;;Password=My Password" name="Events" />
      </connectionStrin gs>
      >
      How can I open a connection to this db in my code?
      >
      Thanks
      >
      Regards
      >
      >

      Comment

      Working...