Referencing Connection Strings in web.config Problems

P

planetmatt

I am trying to copy a text file into a sql server database but I am
having problems with an undeclared variable error. The variable in
question is a reference to the connection string name in the web.config
file. Here is the connectionstring section of my web.config: There
are 2 strings, one called ConLocText and one called ConSQLLocal

*****************************************
<connectionStrings>
<add name="ConLocText" connectionString="Driver={Microsoft Text
Driver (*.txt;
*.csv)};defaultdir=C:\Inetpub\wwwroot\LocationsUpload\FileUploading\LocationCSV;driverid=27;extensions=None,asc,csv,tab,txt;fil=text;filedsn=C:\Program
Files\Common Files\ODBC\Data
Sources\LocationsTxtFile.dsn;maxbuffersize=2048;maxscanrows=25;pagetimeout=5;safetransactions=0;threads=3;uid=admin;usercommitsync=Yes"
providerName="System.Data.Odbc" />
<add name="ConSQLLocal" connectionString="Data
Source=EBIZDEVAPP02;Initial Catalog=Atlas;Persist Security
Info=True;User ID=username;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>
*******************************************

Here is the start of my asp page; the last two lines are the one that
are reporting undeclared variables in visual studio:

*******************************************************

Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Configuration


Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles btnUpload.Click

Try

FileUpload1.SaveAs(MapPath("~/LocationCSV/" & _
FileUpload1.FileName.ToString()))

Dim connections As ConnectionStringSettingsCollection = _
ConfigurationManager.ConnectionStrings

Dim sourcecon As String =
connections(ConLocText).ConnectionString
Dim destcon As String =
connections(ConSQLLocal).ConnectionString

****************************************************

Where and how do I declare these?
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top