Using the Web.Config to set up my SQL database connection string?

前端 未结 8 1381
一整个雨季
一整个雨季 2020-12-24 13:17

Can anyone help me out please? I\'m confused.

I want to set up my connection string so I can just call it from my Web.Config file.

I need a way to call it f

相关标签:
8条回答
  • 2020-12-24 14:14

    Your best bet, starting fresh like you are, is to go grab the enterprise library. They have a configuration tool you can use to wire everything up for you nicely.

    They also have a data access application block which is very useful and documentation filled with good samples.

    http://www.microsoft.com/downloads/details.aspx?FamilyId=90DE37E0-7B42-4044-99BE-F8ECFBBC5B65&displaylang=en

    0 讨论(0)
  • 2020-12-24 14:18

    If you are using SQL Express (which you are), then your login credentials are .\SQLEXPRESS

    Here is the connectionString in the web config file which you can add:

    <connectionStrings>
    <add connectionString="Server=localhost\SQLEXPRESS;Database=yourDBName;Initial Catalog= yourDBName;Integrated Security=true" name="nametoCallBy" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    

    Place is just above the system.web tag.

    Then you can call it by:

    connString = ConfigurationManager.ConnectionStrings["nametoCallBy"].ConnectionString;
    
    0 讨论(0)
提交回复
热议问题