Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 733
  • Last Modified:

Web.config <connectionStrings>

I'm trying to figure out the connection string for Web configs. I have:
Web.Debug.config:
<connectionStrings>
    <add name="ConnectionString"
      connectionString="data source=MY_DEV_DATABASE;persist security info=True;initial catalog=MyCatalog;user id=DevUser;password=123456"
      xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</connectionStrings>

Open in new window

Web.Release.Config:
<connectionStrings>
    <add name="ConnectionString"
      connectionString="data source=MY_DATABASE;persist security info=True;initial catalog=MyCatalog;user id=ProductionUser;password=123456"
      xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</connectionStrings>

Open in new window

Web.config:
<connectionStrings>
    <add name="ConnectionString"
      connectionString="data source=MY_DEV_DATABASE;persist security info=True;initial catalog=MyCatalog;user id=DevUser;password=123456"/>
</connectionStrings>

Open in new window


First, I'm just trying to get this to work in Visual Studio (not publlishing yet), so I'm just concerned about Web.config. As it is, it doesn't work, saying The ConnectionString property has not been initialized.. It works if I do:
  <appSettings>
    <add key="ConnectionString" value="data source=EMNRD-DEV-SQL08;persist security info=True;initial catalog=MMDCoal;user id=CoalMinesQueryUser;password=CoalMinesQueryUser"/>

Open in new window

but I'm trying to user <connectionStrings> instead of <appSettings>

What am I doing wrong?
0
allelopath
Asked:
allelopath
  • 3
  • 3
1 Solution
 
Paul JacksonCommented:
PLease post how you are retrieving the connectionstring in your code
0
 
Paul JacksonCommented:
Connection string in web.config :

<connectionStrings>
    <add name="ConnectionString" providerName="System.Data.SqlClient"
      connectionString="data source=MY_DEV_DATABASE;persist security info=True;initial catalog=MyCatalog;user id=DevUser;password=123456"/>
</connectionStrings>

Open in new window


retrieve in code
using System.Configuration;
...
...

string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

Open in new window

0
 
allelopathAuthor Commented:
Protected WithEvents sqlConn As SqlClient.SqlConnection
sqlConn = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))

Open in new window

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
Paul JacksonCommented:
Change to :

Protected WithEvents sqlConn As SqlClient.SqlConnection
sqlConn = New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

Open in new window


Also need to import the System.Configuration namespace
0
 
allelopathAuthor Commented:
I added this at the top of the file:
Imports System.Configuration

but I get this error on the line you suggested to add (which is undoubtedly what I need)
ConfigurationManager is not declared. It may be inaccessible dues to its protection level.

If I type a . after System.Configuration, ConfigurationManager is not an available selection.
0
 
allelopathAuthor Commented:
Needed to add a reference to System.Configuration.dll.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now