473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

web config

Hi,

I'm trying to setup the Web Config file so that the connection string is
read from it but I'm not sure what I'm doing wrong. The error I get is:
The ConnectionString property has not been initialized.
I also tried to create a virtual path but that didn't work.
My application is at c:\inetpub\wwwroot\web This is where the web.config
file is and it contains the following:

<appSettings>
<add key="connectionstring" value="server=(local)
;trusted_connection=true;database=xxx"/>
</appSettings>
The aspx file contains:

<%@ Page Language="VB" %>
<script runat="server">
Function GetData() As System.Data.IDataReader
Dim connectionString As String
connectionString = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)

Dim queryString As String = "SELECT [tblLink].[quote], [tbllink]
..[linkURL"& _
"] FROM [tblink]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function

Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub

</script>
Thanks

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
10 1537
"connectionstring" and "ConnectionString" are not the same. Change the line-
connectionString=ConfigurationSettings.AppSettings ("ConnectionString")
to
connectionString=ConfigurationSettings.AppSettings ("connectionstring")
"Joe via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:08******************************@DotNetMonste r.com...
Hi,

I'm trying to setup the Web Config file so that the connection string is
read from it but I'm not sure what I'm doing wrong. The error I get is:
The ConnectionString property has not been initialized.
I also tried to create a virtual path but that didn't work.
My application is at c:\inetpub\wwwroot\web This is where the web.config
file is and it contains the following:

<appSettings>
<add key="connectionstring" value="server=(local)
;trusted_connection=true;database=xxx"/>
</appSettings>
The aspx file contains:

<%@ Page Language="VB" %>
<script runat="server">
Function GetData() As System.Data.IDataReader
Dim connectionString As String
connectionString = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)

Dim queryString As String = "SELECT [tblLink].[quote], [tbllink] .[linkURL"& _
"] FROM [tblink]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function

Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub

</script>
Thanks

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2
Thanks. I changed it but I still get the error message that:

The ConnectionString property has not been initialized.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #3
JOe how can u get ConnectionString property error
when u said u have changed it!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #4
I fixed the names so that I tried to make sure it was case sensitive. I've
been going through the code but still can't seem to see what's wrong. I
renamed the connection string, so I have in the Web config:

<appSettings>
<add key="ConnectionString1" value="server=(local)
;trusted_connection=true;database=xx"/>
</appSettings>

aspx file:
Function GetLessons() As System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString1")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblLesson].* FROM
[tblLesson]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function
Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" DataSource="<%#
GetLessons() %>"></asp:DataGrid>
</form>
</body>
</html>

Thanks again

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #5
Joe,

why are you using Data Provider syntax
for a simple data connection ?

System.Data.IDataReader, System.Data.IDbConnection,
and System.Data.IDbConnection all are used when
implementing your own Data Provider.

Please review
http://msdn.microsoft.com/library/de...onnections.asp
to see the info you need to implement a data connection
using any of the Data Providers built into .NET.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Joe via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:00******************************@DotNetMonste r.com...
I fixed the names so that I tried to make sure it was case sensitive. I've
been going through the code but still can't seem to see what's wrong. I
renamed the connection string, so I have in the Web config:

<appSettings>
<add key="ConnectionString1" value="server=(local)
;trusted_connection=true;database=xx"/>
</appSettings>

aspx file:
Function GetLessons() As System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString1")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)

Dim queryString As String = "SELECT [tblLesson].* FROM
[tblLesson]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function
Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" DataSource="<%#
GetLessons() %>"></asp:DataGrid>
</form>
</body>
</html>

Thanks again

Nov 19 '05 #6
Hi,

I think what's happening is that it's not seeing the web.config file since
I tried removing it and got the same error message.

I have the application at: c:/inetpub/wwwroot/web
The web.config file is in this directory and so is the aspx file that I am
testing. I created a virtual directory to this.

Am I missing anything in making this my application root?

Thanks again

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #7
Thanks for all the help. I got it working. It was the case-sensitivity
issue. Also thanks for the advice on the data provider.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #8
Hello Juan,

I disagree with this statement. While these interfaces can be used when implementing
your own data provider, they provide a very nice abstraction layer.

Let's say that I want to interact with either an Oracle or an MSSQL database
in my application, depending on my client's requirements. The quickest/easiest
way to accomplish this is to return an IDbConnection or IDataReader out of
my class's methods. The calling code has no idea about the underlying datastore
and new databases can be added by simply adding a new class.

Very good design...

--
Matt Berther
http://www.mattberther.com
Joe,

why are you using Data Provider syntax
for a simple data connection ?
System.Data.IDataReader, System.Data.IDbConnection, and
System.Data.IDbConnection all are used when implementing your own Data
Provider.

Please review

http://msdn.microsoft.com/library/de...ry/en-us/cpgui
de/html/cpconadonetconnections.asp

to see the info you need to implement a data connection

using any of the Data Providers built into .NET.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
"Joe via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:00******************************@DotNetMonste r.com...
I fixed the names so that I tried to make sure it was case sensitive.
I've been going through the code but still can't seem to see what's
wrong. I renamed the connection string, so I have in the Web config:

<appSettings>
<add key="ConnectionString1" value="server=(local)
;trusted_connection=true;database=xx"/>
</appSettings>
aspx file:
Function GetLessons() As System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString1")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)
Dim queryString As String = "SELECT [tblLesson].* FROM
[tblLesson]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Return dataReader
End Function
Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" DataSource="<%#
GetLessons() %>"></asp:DataGrid>
</form>
</body>
</html>
Thanks again


Nov 19 '05 #9
In general, yes, but the added level of complexity
may cause troubleshooting problems which don't
crop up with the simpler data connection methods.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Matt Berther" <mb******@hotmail.com> wrote in message
news:22***************************@news.microsoft. com...
Hello Juan,

I disagree with this statement. While these interfaces can be used when
implementing your own data provider, they provide a very nice abstraction
layer.

Let's say that I want to interact with either an Oracle or an MSSQL
database in my application, depending on my client's requirements. The
quickest/easiest way to accomplish this is to return an IDbConnection or
IDataReader out of my class's methods. The calling code has no idea about
the underlying datastore and new databases can be added by simply adding a
new class.

Very good design...

--
Matt Berther
http://www.mattberther.com
Joe,

why are you using Data Provider syntax
for a simple data connection ?
System.Data.IDataReader, System.Data.IDbConnection, and
System.Data.IDbConnection all are used when implementing your own Data
Provider.

Please review

http://msdn.microsoft.com/library/de...ry/en-us/cpgui
de/html/cpconadonetconnections.asp

to see the info you need to implement a data connection
using any of the Data Providers built into .NET.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
"Joe via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:00******************************@DotNetMonste r.com...
I fixed the names so that I tried to make sure it was case sensitive.
I've been going through the code but still can't seem to see what's
wrong. I renamed the connection string, so I have in the Web config:

<appSettings>
<add key="ConnectionString1" value="server=(local)
;trusted_connection=true;database=xx"/>
</appSettings>
aspx file:
Function GetLessons() As System.Data.IDataReader
Dim strConnection As String
strConnection = ConfigurationSettings.AppSettings
("ConnectionString1")
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(strConnection)
Dim queryString As String = "SELECT [tblLesson].* FROM
[tblLesson]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)
Return dataReader
End Function
Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server" DataSource="<%#
GetLessons() %>"></asp:DataGrid>
</form>
</body>
</html>
Thanks again


Nov 19 '05 #10
Glad you got this solved. From first look, I thought you didn't import the
System.Configuration Namespace. I didn't see it anywere in your code. The
fully namespace with class name is
System.Configuration.ConfigurationSettings.AppSett ings. But, look like this
wasn't it. Just wanted to give others a heads up on this. People sometimes
forget this when not using VS.NET to compile their code.
"Joe via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:08******************************@DotNetMonste r.com...
Hi,

I'm trying to setup the Web Config file so that the connection string is
read from it but I'm not sure what I'm doing wrong. The error I get is:
The ConnectionString property has not been initialized.
I also tried to create a virtual path but that didn't work.
My application is at c:\inetpub\wwwroot\web This is where the web.config
file is and it contains the following:

<appSettings>
<add key="connectionstring" value="server=(local)
;trusted_connection=true;database=xxx"/>
</appSettings>
The aspx file contains:

<%@ Page Language="VB" %>
<script runat="server">
Function GetData() As System.Data.IDataReader
Dim connectionString As String
connectionString = ConfigurationSettings.AppSettings
("ConnectionString")

Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)

Dim queryString As String = "SELECT [tblLink].[quote],
[tbllink]
.[linkURL"& _
"] FROM [tblink]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function

Sub Page_Load(sender As Object, e As EventArgs)
Page.Databind()
End Sub

</script>
Thanks

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
3
by: Richard Lewis Haggard | last post by:
I have a test application that is calling an assembly that reads some strings out of a config file. Normally, this assembly supports a web application and the information can be read just fine....
13
by: Khodr | last post by:
Hello, I am using VS.NET 2003 and vb. I build my application MyApp and it generates MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. Great and no problem! I need to...
20
by: tomerfiliba | last post by:
hey i've been seeing lots of config-file-readers for python. be it ConfigObj (http://www.voidspace.org.uk/python/configobj.html) or the like. seems like a trend to me. i came to this conclusion...
11
by: TARUN | last post by:
Hello All I need to ask about the configuration file in .NET, There are Two config File 1. Web Config 2. Machine config I understand the the usage of Web config , but not able to understand...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
10
by: eagle | last post by:
I have a web.config in my application that contains the connection strings to all my datasources. I want to move these connection strings to another web config up the folder hierarchy so that all...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a app that uses several membership/role providers. I can list these Providers with the code: Dim rootWebConfig1 As Configuration rootWebConfig1 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.