Saturday, March 31, 2012

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:

<%@dotnet.itags.org. 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"connectionstring" and "ConnectionString" are not the same. Change the line-
connectionString=ConfigurationSettings.AppSettings ("ConnectionString")
to
connectionString=ConfigurationSettings.AppSettings ("connectionstring")

"Joe via DotNetMonster.com" <forum@.DotNetMonster.com> wrote in message
news:086ed6be9bd842dbabf1aa433aa7fdf3@.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
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
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!
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
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/d...connections.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 Espaol
Ven, y hablemos de ASP.NET...
======================

"Joe via DotNetMonster.com" <forum@.DotNetMonster.com> wrote in message
news:00ad191e3d8f47f6a6ba782e53ddcb5e@.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
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
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
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/d...ary/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 Espaol
> Ven, y hablemos de ASP.NET...
> ======================
> "Joe via DotNetMonster.com" <forum@.DotNetMonster.com> wrote in message
> news:00ad191e3d8f47f6a6ba782e53ddcb5e@.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
>
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 Espaol
Ven, y hablemos de ASP.NET...
======================

"Matt Berther" <mberther@.hotmail.com> wrote in message
news:221a09c78550fb8c6ecc5d1d2e129@.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/d...ary/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 Espaol
>> Ven, y hablemos de ASP.NET...
>> ======================
>> "Joe via DotNetMonster.com" <forum@.DotNetMonster.com> wrote in message
>> news:00ad191e3d8f47f6a6ba782e53ddcb5e@.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
>>>
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" <forum@.DotNetMonster.com> wrote in message
news:086ed6be9bd842dbabf1aa433aa7fdf3@.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

0 comments:

Post a Comment