can't retrieve connection string from web.config

J

Jon Paal

..net 2.0

can't retrieve connection string from web.config, always returns error message -- what's missing ??

======web.config =========

<appSettings>
<connectionStrings>
<add name="NorthwindConn"
connectionString="Server='local'; database='NORTHWIND'; Trusted_Connection=False; uid=sa;pwd=*****"
providerName="System.Data.SqlClient" />
</connectionStrings>
</appSettings>

========== class =========

Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System.Configuration
Imports System.Web.Configuration

Imports System.IO

Public Class SyndicateHandler
Implements IHttpHandler
Private _errorMessage As String = String.Empty

Public Sub ProcessRequest(context As HttpContext) _
Implements System.Web.IHttpHandler.ProcessRequest

Dim sReturn As String = String.Empty
Dim sConn As String = String.Empty

try
' Get the ConnectionStrings collection.
Dim connections As ConnectionStringSettingsCollection = _
ConfigurationManager.ConnectionStrings

sConn = connections("NorthwindConn").ConnectionString

sReturn &= sConn

catch ex As Exception
sReturn &= ex.Message
end try
.....
End Sub 'ProcessRequest

End Class
 
G

gella

hi,
use this..
======web.config =========
<appSettings><add key="conString"
value=" data source=datasource;uid=sa;pwd=*****;initial
catalog=NORTHWIND"/>
========== class =========
Imports System.Data.SqlClient
Imports System.Web.Configuration


-------------------------------------------------------------
to retrive connection string use following
-----------------------------------------------------------
dim constr as string

constr = ConfigurationSettings.AppSettings("conString")
con = New SqlConnection(constr)
regards,
gella

-------------------------------------------------------------------------------------------------------------------
 
J

Juan T. Llibre

<connectionStrings> doesn't go inside <appSettings>
Include it after <configuration>

Also, don't include it inside <system.web>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top