Storing a connection string
<configuration>
<connectionStrings>
<add
name = "my"
connectionString = "server=local;database=myDB;
uid=WebUser;pwd=password" />
</connectionStrings>
</configuration>
Retrieving a connection string (VB)
Public Sub Page_Load (sender As Object, e As EventArgs)
...
Dim dbConnection as New _
SqlConnection(ConfigurationSettings.ConnectionStrings("my"))
...
End Sub
Retrieving a connection string (C#)
public void Page_Load (Object sender, EventArgs e)
{
...
SqlConnection dbConnection = new
SqlConnection(ConfigurationSettings.ConnectionStrings["my"]);
...
}
Related examples in the same category