Referencing Connection Strings in web.config Problems

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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?

.



Relevant Pages

  • Re: ADO connections question
    ... Function CreateADOObjects(ConnectionString as string) ... you'll see this error if the connection has not been ... I have a specific login form that calls the dbLogin function as shown ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: ADO connections question
    ... I have a module which creates the ADO connection object to validates the ... Function dbLogin(txtUser As String, txtPword As String, txtServer As String, ... I have a specific login form that calls the dbLogin function as shown below: ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: ExecuteReader requires an open and available Connection.
    ... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • DTS Transformation Data Task Errors
    ... Dim oIniFile As New IniFile ... Dim sServerName As String = oIniFile.GetString("Source Connection", ... ;ServerName* - String value representing the name or ip address of the ...
    (microsoft.public.sqlserver.dts)
  • Re: ExecuteReader requires an open and available Connection.
    ... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
    (microsoft.public.dotnet.framework.aspnet)