connection string in Web.config

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shhntl
    New Member
    • Jul 2007
    • 5

    connection string in Web.config

    How do I add a connection string using trusted connection in the Web.config.
    All i know is the following statement to declare the connection srting

    <appSettings>

    <add key="myConnstr" value="server=_ ;database=_;use r=_;pass=_;" />

    </appSettings>

    But what do i do to get a trusted connection, so that i donot require to give the username and password
  • shhntl
    New Member
    • Jul 2007
    • 5

    #2
    hi ,
    finally after 2 days of search i found the answer. I tried deleting the thread, but could not find the link, so just thought of posting the answer so that someone else can use it.

    <connectionStri ngs>
    <add name="con" connectionStrin g="SQLstring" providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>
    Dim strCon As String = System.Configur ation.Configura tionManager.Con nectionStrings( "con").Connecti onString

    Dim con As New SqlConnection(s trCon)
    con.open()

    if you were to to use key it would have to be:

    <appSettings>
    <add key="SQLconnect ion" value="SQLstrin g"/>
    </appSettings>
    dim strCon as string = System.Configur ation.Configura tionManager.App Settings("SQLco nnection")
    dim con as new sqlConnection(s trCon)

    con.open()

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Well done - thanks for sharing the solution :).

      Comment

      Working...