Jay1b Posted March 10, 2006 Posted March 10, 2006 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 Quote
Administrators PlausiblyDamp Posted March 10, 2006 Administrators Posted March 10, 2006 Don't have VS handy on this PC so I haven't tested it but have you tried Dim conn As New SqlConnection("ConnectionStrings:connCReq") if not I'll have a proper look at it later. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 10, 2006 Author Posted March 10, 2006 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' Quote
Administrators PlausiblyDamp Posted March 10, 2006 Administrators Posted March 10, 2006 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) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 10, 2006 Author Posted March 10, 2006 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. Quote
pelikan Posted March 12, 2006 Posted March 12, 2006 see http://support.microsoft.com/?kbid=823679 Quote IN PARVUM MULTUM
Jay1b Posted March 13, 2006 Author Posted March 13, 2006 Thanks Pelikan, but unfortunately that only applies to Framework 1.0 and 1.1, i'm running 2005 - which is 2.0. Quote
Administrators PlausiblyDamp Posted March 13, 2006 Administrators Posted March 13, 2006 The classes should be in the System.Configuration.Dll if you've referenced that it should work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 13, 2006 Author Posted March 13, 2006 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. Quote
Jay1b Posted March 16, 2006 Author Posted March 16, 2006 Does anybody have any idea's what i'm doing wrong? Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.