Opening connection to db

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

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

<connectionStrings>
<add
providerName="System.Data.SqlClient" connectionString="Data
Source=MySQLServer.net;Initial Catalog=&quot;MyDB&quot;;Persist Security
Info=True;User ID=&quot;UID&quot;;Password=MyPassword" name="Events" />
</connectionStrings>

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

Thanks

Regards
 
Hi

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

<connectionStrings>
<add
providerName="System.Data.SqlClient" connectionString="Data
Source=MySQLServer.net;Initial Catalog=&quot;MyDB&quot;;Persist Security
Info=True;User ID=&quot;UID&quot;;Password=MyPassword" name="Events" />
</connectionStrings>

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

Thanks

Regards

This following article will help you:

http://msdn.microsoft.com/en-us/library/ms998300.aspx
 
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["Events"].ConnectionString);
conn.Open();
--Peter
 
Back
Top