Sunday, 23 November 2008
DotNetSpace, Asp.net 2.0 tutorials and code examples. ajax, log4net...
Home arrow Articles arrow General Articles arrow Database Connection How To
 
Main Menu
Home
Articles
News
Links
Search








BiraJones




Database Connection How To Print E-mail
Friday, 18 August 2006

 How to configure a database connection (using SQL Server in this example):

    //The connection string to be used in web.config file.
    //It is configured to use SQL server express 2005 version.
    <connectionStrings>
        <add name="myConnectionString"
             connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=databaseName;Persist Security Info=True;User ID=sa;Password=123"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
... 

How to use: 

     SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

    conn.Open();
    ....//any code...
    conn.Close();

 

 

Last Updated ( Tuesday, 31 October 2006 )
 
< Prev   Next >
Popular
Polls
-->*/?>

Which language will you choose for coding with Visual Studio .NET?
 
-->*/?>

Is ASP.NET better than Java / JSP frameworks?
 

© 2008 DotNetSpace
Joomla! is Free Software released under the GNU/GPL License.