Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

 

I'm trying to use a connection string saved in the web.config, but i'm getting an error

 

Dim conn As New SqlConnection("ConnectionStrings:connCReq.ProviderName")

 

 <connectionStrings>
   <add name="connCReq" connectionString="Data Source=RA\SQLExpress;Initial Catalog=CReq;User ID=ASP;Password=password"
     providerName="System.Data.SqlClient" />
     </connectionStrings>

 

If i copy the ACTUAL connection string in, it works fine. Obviously i dont wish to do this as that would be besides the point of the web.config.

 

Can anybody spot whats wrong please?

 

Thanks

Posted

Thanks, but unfortunately i have tried it.... it returns the following error

 

'Format of the initialization string does not conform to specification starting at index 0'

  • Administrators
Posted

Try something like

Dim conf as Configuration  = Configuration.GetWebConfiguration("~/")
Dim section as ConnectionStringsSection = conf.Sections("connectionStrings")
Dim conn As New SqlConnection(section.ConnectionStrings("connCReq").ConnectionString)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

hmmm... Strange one....

 

Getwebconfiguration is not a member of system.configuration.configuration

 

Tried importing system.configuration as well...

 

I ran a search on google and it found the below

Dim cnfg As System.Configuration.Configuration
cnfg = System.Configuration.Configuration.GetWebConfiguration(Request.ApplicationPath)
Dim trace As System.Web.Configuration.TraceSection
trace = DirectCast(cnfg.GetSection("system.web/trace"), 
System.Web.Configuration.TraceSection)
trace.Enabled = True
cnfg.Update()

 

Which states its there as well.... I've almost tried referencing system.configuration, incase its that.... but it didnt change anything.

Posted

I've done that.... Or at least i think i have.

 

Website -> Add Reference... -> (Select System.Configuration) -> Click OK.

 

Also tried -

 

Website -> Start Options... -> References -> Add Reference... -> (Select System.Configuration) -> Click OK. (Box still remains blank).

 

I try this for "Imports System.Data.SqlClient" and it adds it to the box, and creates a 'bin' folder with the dll in it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...