How do I read cnnection string from web config file
-
I had the following code:
Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstring
he code above returned the error below: "Object not sent to an instance of an object" on the lineconstr =mycon.connectionstring
Please where did I get it wrong. Thanks -
I had the following code:
Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstring
he code above returned the error below: "Object not sent to an instance of an object" on the lineconstr =mycon.connectionstring
Please where did I get it wrong. ThanksTo read a connection string from web.config using
WebConfigurationManager
, all you need to do is:Dim constr As String = WebConfigurationManager.ConnectionStrings("CString1")
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
-
I had the following code:
Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstring
he code above returned the error below: "Object not sent to an instance of an object" on the lineconstr =mycon.connectionstring
Please where did I get it wrong. Thanksin web.config:
<appSettings> <add key="ConnString" value="server=(local);database=Northwind;Integrated Security=SSPI" /> </appSettings>
call in u r web page asImports System.Web.Configuration dim constr as string constr=ConfigurationManager.ConnectionStrings("ConnString").ConnectionString
use this hope this helps