Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs)
Dim query as String = String.Empty
...
query = String.Format("SELECT * FROM dbo.documents WHERE ") & query
End Sub
I need "query" to be global and accessible everywhere.
How can I do this?
Thanks,
Miguel 41 10495
If you want query variable to be accessed in all the pages then declare that
variable in application scope or put it in cache.
--
Saravana http://dotnetjunkies.com/WebLog/saravana/ www.ExtremeExperts.com
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
With a web app, generally your global variables should be stored in the
Application Object or Cache object. This way they are explicity made
accessible to all code in your app.
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
Hello,
Can you tell me how to store the global variables in the Application
Object?
What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks,
Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:St***@Orr.net: With a web app, generally your global variables should be stored in the Application Object or Cache object. This way they are explicity made accessible to all code in your app.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End
Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
You could also insert a key in the application's
web.config and read it whenever you need it.
First, include this in your web.config :
<appSettings>
<add key="query1" value="SELECT * FROM dbo.documents WHERE"/>
</appSettings>
Then, retrieve it with this :
Dim query1 As String = System.Configuration.ConfigurationSettings.AppSett ings("query1")
The value for query1 will be available at the Application scope level.
Values read from the web.config file are always of type String.
This method has the advantage that you can have multiple
queries stored in web.config, to be used as needed.
Juan T. Llibre
===========
"Saravana" <sa******@sct.co.in> wrote in message
news:4m*****************@news.cpqcorp.net... If you want query variable to be accessed in all the pages then declare that variable in application scope or put it in cache.
-- Saravana http://dotnetjunkies.com/WebLog/saravana/ www.ExtremeExperts.com
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:OP**************@TK2MSFTNGP09.phx.gbl... Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
'To store a variable:
Application.Lock()
Application("MyVar")="whatever"
Application.Unlock()
'to retrieve the variable:
Dim s as String = Application("MyVar").ToString()
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: With a web app, generally your global variables should be stored in the Application Object or Cache object. This way they are explicity made accessible to all code in your app.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... > Hello, > > I am working on an ASP.NET / VB page and I created a variable "query": > > Sub Page_Load(sender As Object, e As System.EventArgs) > Dim query as String = String.Empty > ... > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > End > > Sub > > I need "query" to be global and accessible everywhere. > How can I do this? > > Thanks, > Miguel >
Wouldn't it be better to use Cache?
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl... 'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock()
'to retrieve the variable: Dim s as String = Application("MyVar").ToString()
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: With a web app, generally your global variables should be stored in the Application Object or Cache object. This way they are explicity made accessible to all code in your app.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in
message news:OP**************@TK2MSFTNGP09.phx.gbl... > Hello, > > I am working on an ASP.NET / VB page and I created a variable
"query": > > Sub Page_Load(sender As Object, e As System.EventArgs) > Dim query as String = String.Empty > ... > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > End > > Sub > > I need "query" to be global and accessible everywhere. > How can I do this? > > Thanks, > Miguel >
Steve,
Doesn't serializing the access to the Application object
using the Lock and UnLock methods mean you have to
accept a considerable performance hit ?
It seems to me that, although using the Application object
gets the job done, it does so in a very inefficient way.
That's why I suggested adding a key in web.config,
and retrieving *that* whenever needed.
Juan T. Llibre
===========
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl... 'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock()
'to retrieve the variable: Dim s as String = Application("MyVar").ToString()
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: With a web app, generally your global variables should be stored in the Application Object or Cache object. This way they are explicity made accessible to all code in your app.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... > Hello, > > I am working on an ASP.NET / VB page and I created a variable "query": > > Sub Page_Load(sender As Object, e As System.EventArgs) > Dim query as String = String.Empty > ... > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > End > > Sub > > I need "query" to be global and accessible everywhere. > How can I do this? > > Thanks, > Miguel >
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
Steve, why do you need to serialize writes? Updates maybe, but why simple
writes?
John Saunders
Searching the underlying data structure to see if and where the key
exists wouldn't be an atomic operation, something could change in
betwen the 'find the entry' and the 'insert' or 'write' operation.
Fortunately, the docs say the Application object is safe for
multi-threaded access. The Lock / Unlock would't be required for a
single write operation. Reflector shows it uses a slightly more
granular reader/writer lock underneath for thread safety:
this._lock.AcquireWrite();
try
{
base.BaseSet(name, value);
}
finally
{
this._lock.ReleaseWrite();
}
--
Scott http://www.OdeToCode.com/blogs/scott/
On Tue, 14 Dec 2004 13:13:43 -0500, "John Saunders" <johnwsaundersiii
at hotmail.com> wrote: "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
Steve, why do you need to serialize writes? Updates maybe, but why simple writes?
John Saunders
I agree it's safe. It's just a lot slower.
Juan T. Llibre
===========
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:96********************************@4ax.com... Searching the underlying data structure to see if and where the key exists wouldn't be an atomic operation, something could change in betwen the 'find the entry' and the 'insert' or 'write' operation.
Fortunately, the docs say the Application object is safe for multi-threaded access. The Lock / Unlock would't be required for a single write operation. Reflector shows it uses a slightly more granular reader/writer lock underneath for thread safety:
this._lock.AcquireWrite(); try { base.BaseSet(name, value);
} finally { this._lock.ReleaseWrite(); }
-- Scott http://www.OdeToCode.com/blogs/scott/
On Tue, 14 Dec 2004 13:13:43 -0500, "John Saunders" <johnwsaundersiii at hotmail.com> wrote:
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
Steve, why do you need to serialize writes? Updates maybe, but why simple writes?
John Saunders
Guys,
I am even more confused than I was before...
....i am just starting.
So Aplication, Cache or Web.Config?
Maybe I should mention that I only need to access the query variable in
the same page where I have this script.
Basically this script creates the SQL code to be used on a dataset on
that page using the values passed on the URL and a list of rules.
Web.Config seems a really general solution because, if I am not wrong,
it makes available the variable to all pages.
Do you think it's a bad solution when I only need it on the same page of
the script?
About Aplication I am a little bit confused to. :-). I should place the
code you mention just before the function PAGE_LOAD.
Sorry for so many questions but I am starting ASP.NET and something seem
really obvious and easy to me but other are completely strange even if
they are simple.
Thanks,
Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:no***********@nowhere.com: I agree it's safe. It's just a lot slower. Juan T. Llibre =========== "Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:96********************************@4ax.com... Searching the underlying data structure to see if and where the key exists wouldn't be an atomic operation, something could change in betwen the 'find the entry' and the 'insert' or 'write' operation.
Fortunately, the docs say the Application object is safe for multi-threaded access. The Lock / Unlock would't be required for a single write operation. Reflector shows it uses a slightly more granular reader/writer lock underneath for thread safety:
this._lock.AcquireWrite(); try { base.BaseSet(name, value);
} finally { this._lock.ReleaseWrite(); }
-- Scott http://www.OdeToCode.com/blogs/scott/
On Tue, 14 Dec 2004 13:13:43 -0500, "John Saunders" <johnwsaundersiii at hotmail.com> wrote:
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
Steve, why do you need to serialize writes? Updates maybe, but why simple writes?
John Saunders
Hi, Miguel.
re: So Aplication, Cache or Web.Config?
Application would be overkill, and consumes the most
resources both in terms of ram and cpu contention.
Cache is doable, but the ram consumed is permanent.
I'd go with Web.config.
Maybe I should mention that I only need to access the query variable in the same page where I have this script.
If that's the case, you don't need a variable.
However, you should consider not only placing
that query in web.config, but also placing your
database connection information in the web.config, too.
That will keep your server access info ( account and password )
away from prying eyes. If you place your account and password
in the page's code, it could be revealed.
A fourth alternative ( I hope this doesn't confuse you )
would be to create a database access class and compile
it as an assembly. Then, you could reference the assembly
any time you need to connect to your data.
For your purposes, using web.config is OK.
If traffic gets heavy, consider compiling a db access assembly.
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Guys,
I am even more confused than I was before... ...i am just starting.
So Aplication, Cache or Web.Config?
Maybe I should mention that I only need to access the query variable in the same page where I have this script.
Basically this script creates the SQL code to be used on a dataset on that page using the values passed on the URL and a list of rules.
Web.Config seems a really general solution because, if I am not wrong, it makes available the variable to all pages.
Do you think it's a bad solution when I only need it on the same page of the script?
About Aplication I am a little bit confused to. :-). I should place the code you mention just before the function PAGE_LOAD.
Sorry for so many questions but I am starting ASP.NET and something seem really obvious and easy to me but other are completely strange even if they are simple.
Thanks, Miguel "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: I agree it's safe. It's just a lot slower. Juan T. Llibre =========== "Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:96********************************@4ax.com... > Searching the underlying data structure to see if and where the key > exists wouldn't be an atomic operation, something could change in > betwen the 'find the entry' and the 'insert' or 'write' operation. > > Fortunately, the docs say the Application object is safe for > multi-threaded access. The Lock / Unlock would't be required for a > single write operation. Reflector shows it uses a slightly more > granular reader/writer lock underneath for thread safety: > > this._lock.AcquireWrite(); > try > { > base.BaseSet(name, value); > > } > finally > { > this._lock.ReleaseWrite(); > } > > -- > Scott > http://www.OdeToCode.com/blogs/scott/ > > On Tue, 14 Dec 2004 13:13:43 -0500, "John Saunders" <johnwsaundersiii > at hotmail.com> wrote: > >>"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message >>news:uB**************@TK2MSFTNGP11.phx.gbl... >>> Steve, >>> >>> Doesn't serializing the access to the Application object >>> using the Lock and UnLock methods mean you have to >>> accept a considerable performance hit ? >> >>Steve, why do you need to serialize writes? Updates maybe, but why >>simple >>writes? >> >>John Saunders >> >
Hi,
I already have the database connection information on my web.config
file.
I followed your advice and include the query (queryDocuments) variable
in the web.config. However it's not working.
My interpretation is that the script is not updating that value.
The SQL code used is always the same even if queryDocuments change.
I believe I am missing something here.
Here is the code on my page:
....
ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSett ings("CON_STR_conTes")
%>'
DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSett ings("CON_DBT_conTes")
%>'
CommandText='<%#
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
%>'
....
See what I did on CommandText?
Now check my script also on that page:
<script runat="server">
Sub Page_Load(sender As Object, e As System.EventArgs)
Dim queryDocuments As String =
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
If Request.QueryString("pesquisar") Is Nothing Then
queryDocuments = "SELECT * FROM dbo.documents"
Else
queryDocuments = ""
Dim keywords as string()
keywords = Request.QueryString("pesquisar").Split(CChar(" "))
Dim i As Int32
For i = 0 To keywords.Length
queryDocuments += String.Format("CONTAINS (*, '{0}') ",
keywords(i))
If i + 1 = keywords.Length Then
i = keywords.Length
Exit For
End If
queryDocuments += " AND "
Next
queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE
") & queryDocuments
End If
Response.Write(queryDocuments)
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("queryDocuments"))
End Sub
</script>
On the Web.Config I have this:
<add key="queryDocuments" value="SELECT * FROM dbo.documents"/>
What am I doing wrong?
Thanks,
Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:no***********@nowhere.com: Hi, Miguel.
re: So Aplication, Cache or Web.Config?
Application would be overkill, and consumes the most resources both in terms of ram and cpu contention.
Cache is doable, but the ram consumed is permanent.
I'd go with Web.config.
Maybe I should mention that I only need to access the query variable in
the same page where I have this script.
If that's the case, you don't need a variable.
However, you should consider not only placing that query in web.config, but also placing your database connection information in the web.config, too.
That will keep your server access info ( account and password ) away from prying eyes. If you place your account and password in the page's code, it could be revealed.
A fourth alternative ( I hope this doesn't confuse you ) would be to create a database access class and compile it as an assembly. Then, you could reference the assembly any time you need to connect to your data.
For your purposes, using web.config is OK. If traffic gets heavy, consider compiling a db access assembly. Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... Guys,
I am even more confused than I was before... ...i am just starting.
So Aplication, Cache or Web.Config?
Maybe I should mention that I only need to access the query variable in
the same page where I have this script.
Basically this script creates the SQL code to be used on a dataset on that page using the values passed on the URL and a list of rules.
Web.Config seems a really general solution because, if I am not wrong, it makes available the variable to all pages.
Do you think it's a bad solution when I only need it on the same page of
the script?
About Aplication I am a little bit confused to. :-). I should place the
code you mention just before the function PAGE_LOAD.
Sorry for so many questions but I am starting ASP.NET and something seem
really obvious and easy to me but other are completely strange even if
they are simple.
Thanks, Miguel "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: I agree it's safe. It's just a lot slower. Juan T. Llibre =========== "Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:96********************************@4ax.com... > Searching the underlying data structure to see if and where the key > exists wouldn't be an atomic operation, something could change in > betwen the 'find the entry' and the 'insert' or 'write' operation. > > Fortunately, the docs say the Application object is safe for > multi-threaded access. The Lock / Unlock would't be required for a > single write operation. Reflector shows it uses a slightly more > granular reader/writer lock underneath for thread safety: > > this._lock.AcquireWrite(); > try > { > base.BaseSet(name, value); > > } > finally > { > this._lock.ReleaseWrite(); > } > > -- > Scott > http://www.OdeToCode.com/blogs/scott/ > > On Tue, 14 Dec 2004 13:13:43 -0500, "John Saunders" > <johnwsaundersiii > at hotmail.com> wrote: > >>"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message >>news:uB**************@TK2MSFTNGP11.phx.gbl... >>> Steve, >>> >>> Doesn't serializing the access to the Application object >>> using the Lock and UnLock methods mean you have to >>> accept a considerable performance hit ? >> >>Steve, why do you need to serialize writes? Updates maybe, but why >>simple >>writes? >> >>John Saunders >> >
Let's do this by parts, Miguel,
to see if we can nail the problem.
You do have
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="queryDocuments" value="SELECT * FROM dbo.documents"/>
</appSettings>
' other configuration stuff...
<system.web>
</system.web>
</configuration>
or similar, in your web.config, right ?
Make sure of the placement of <appSettings> ( below <configuration> )
Please write this code as a file "test.aspx", and run it,
to see if "SELECT * FROM dbo.documents" is written
test.aspx:
----------
<%@ Page Language="VB" %>
<head>
<title>Retrieve value from web.config</title>
</head>
<body>
<script runat="server">
Public Sub Page_Load(Sender As System.Object, E As System.EventArgs)
Dim queryDocs As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Label1.Text = queryDocs
End Sub
</script>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
Run it, and let us know if the queryDocuments key is retrieved.
Then, once we know that, we can check other possibilities.
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl... I followed your advice and include the query (queryDocuments) variable in the web.config. However it's not working.
Hello,
About my web.config file is as you said.
I ran the test file you sent me and here is the result:
SELECT * FROM dbo.documents
I knew already this was going to be result because in my script I placed
the code line "
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("queryDocuments"))"
right after "Sub Page_Load(sender As Object, e As System.EventArgs)" and
I got the value I have in web.config file.
What should I do know?
Thanks,
Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:no***********@nowhere.com: Let's do this by parts, Miguel, to see if we can nail the problem.
You do have
<?xml version="1.0"?> <configuration> <appSettings> <add key="queryDocuments" value="SELECT * FROM dbo.documents"/> </appSettings> ' other configuration stuff... <system.web> </system.web> </configuration>
or similar, in your web.config, right ? Make sure of the placement of <appSettings> ( below <configuration> )
Please write this code as a file "test.aspx", and run it, to see if "SELECT * FROM dbo.documents" is written
test.aspx: ----------
<%@ Page Language="VB" %> <head> <title>Retrieve value from web.config</title> </head> <body> <script runat="server"> Public Sub Page_Load(Sender As System.Object, E As System.EventArgs) Dim queryDocs As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") Label1.Text = queryDocs End Sub </script> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" Runat="server" Text=""></asp:Label> </div> </form> </body> </html>
Run it, and let us know if the queryDocuments key is retrieved.
Then, once we know that, we can check other possibilities.
Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl... I followed your advice and include the query (queryDocuments) variable in the web.config. However it's not working.
OK, that's good.
Next question:
You are retrieving the query's value twice.
Once with:
CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with
Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrive it
sets the value permanently ?
If you have a permanent value for CommandText,
then nothing you do with "queryDocuments", later,
will affect the value for "CommandText".
Why are you retrieving that value twice,
and assigning the same value to two different variables ?
( CommandText and queryDocuments )
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:Oj**************@TK2MSFTNGP11.phx.gbl... Hello, About my web.config file is as you said. I ran the test file you sent me and here is the result: SELECT * FROM dbo.documents What should I do know?
Accessing the web.config is rather slow.
Application is faster because it's all in memory and doesn't need to access
the hard drive. (except maybe it's not fast when the server is under heavy
load.)
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
It seems to me that, although using the Application object gets the job done, it does so in a very inefficient way.
That's why I suggested adding a key in web.config, and retrieving *that* whenever needed. Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:u5**************@TK2MSFTNGP10.phx.gbl... 'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock()
'to retrieve the variable: Dim s as String = Application("MyVar").ToString()
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: With a web app, generally your global variables should be stored in the Application Object or Cache object. This way they are explicity made accessible to all code in your app.
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl... > Hello, > > I am working on an ASP.NET / VB page and I created a variable > "query": > > Sub Page_Load(sender As Object, e As System.EventArgs) > Dim query as String = String.Empty > ... > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > End > > Sub > > I need "query" to be global and accessible everywhere. > How can I do this? > > Thanks, > Miguel >
re: Application is faster because it's all in memory
Both cache data and compiled, cached,
aspx pages are also "in memory".
Regarding performance concerns, see : http://msdn.microsoft.com/library/de...ationState.asp
Application-state variables are, in effect, global variables for a given
ASP.NET application. Like client-side application developers,
ASP.NET programmers should always consider the impact of
storing anything as a global variable.
The following issues are particularly important in this context:
1. The memory impact of storing something in application state.
The memory occupied by variables stored in application state
is not released until the value is either removed or replaced
That is not a concern when using web.config.
2. The concurrency and synchronization implications of storing
and accessing a global variable within a multithreaded server environment.
That is not a concern when using web.config.
3. The scalability implications of storing and accessing
a global variable within a multithreaded server environment.
That is not a concern when using web.config.
Regarding Locks ( like the ones you recommended ) : Application.Lock() Application.Unlock()
Locks should be used whenever an attempt is made to write
or update a file. Locks that protect global resources are
themselves global, and code running on multiple threads
accessing global resources ultimately ends up contending
on these locks.
This causes the operating system to block the worker threads
until the lock becomes available. In high-load server environments,
this blocking can cause severe thread thrashing on the system.
On multiprocessor systems, it can lead to processor underutilization
(since all the threads for a processor theoretically can be stalled while
waiting for a shared lock) and significant drops in overall scalability.
That is not a concern when using web.config.
4. The life-cycle implications of information stored in application state.
That is not a concern when using web.config.
5. Application state is not shared across a Web farm
(in which an application is hosted by multiple servers)
or a Web garden (in which an application is hosted by
multiple processes on the same server).
Variables stored in application state in either of those scenarios
are global only to the particular process in which the application
is running.
Each application process can have different values.
Therefore, you cannot rely on application state to store
unique values or update global counters, for example,
in Web farm and Web garden scenarios.
That is not a concern when using web.config.
re: (except maybe it's not fast when the server is under heavy load.)
That alone would make me shy away from the use of Global.asax's
Application_OnStart as a data repository to be accessed during
an application's lifetime.
In short, although speed is not the only consideration, I haven't
seen *anybody* recommending the use of variables stored
at the Global Application level, except for very small tidbits
which are updated once in a blue moon.
Probably the fastest way to retrieve a small amount of stored
data would be to declare it as a variable in an assembly,
and to retrieve and cache the result.
For not-too-intensive traffic websites, short strings stored in
web.config is one of the easiest storage/retrieval methods to
implement, is reliable, and is fast enough.
Juan T. Llibre
===========
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
It seems to me that, although using the Application object gets the job done, it does so in a very inefficient way.
That's why I suggested adding a key in web.config, and retrieving *that* whenever needed. Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:u5**************@TK2MSFTNGP10.phx.gbl... 'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock()
'to retrieve the variable: Dim s as String = Application("MyVar").ToString()
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: > With a web app, generally your global variables should be stored in > the > Application Object or Cache object. This way they are explicity made > accessible to all code in your app. > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in > message > > news:OP**************@TK2MSFTNGP09.phx.gbl... > > Hello, > > > > I am working on an ASP.NET / VB page and I created a variable > > "query": > > > > Sub Page_Load(sender As Object, e As System.EventArgs) > > Dim query as String = String.Empty > > ... > > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > > End > > > > Sub > > > > I need "query" to be global and accessible everywhere. > > How can I do this? > > > > Thanks, > > Miguel > >
web.config is loaded into memory when the app starts, isn't that correct?
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to
access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
It seems to me that, although using the Application object gets the job done, it does so in a very inefficient way.
That's why I suggested adding a key in web.config, and retrieving *that* whenever needed. Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:u5**************@TK2MSFTNGP10.phx.gbl... 'To store a variable: Application.Lock() Application("MyVar")="whatever" Application.Unlock()
'to retrieve the variable: Dim s as String = Application("MyVar").ToString()
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl... Hello,
Can you tell me how to store the global variables in the Application Object? What should the code be and where should I place it?
I am just starting with ASP.NET.
Thanks, Miguel
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:St***@Orr.net: > With a web app, generally your global variables should be stored in
the> Application Object or Cache object. This way they are explicity made > accessible to all code in your app. > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in > message > > news:OP**************@TK2MSFTNGP09.phx.gbl... > > Hello, > > > > I am working on an ASP.NET / VB page and I created a variable > > "query": > > > > Sub Page_Load(sender As Object, e As System.EventArgs) > > Dim query as String = String.Empty > > ... > > query = String.Format("SELECT * FROM dbo.documents WHERE ") &
query> > End > > > > Sub > > > > I need "query" to be global and accessible everywhere. > > How can I do this? > > > > Thanks, > > Miguel > >
Hi Kevin,
I am not sure. If it is like that u mean that the change of value I do
in my script on page_load doesn't change the default value?
Thanks,
Miguel
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:ks******@takempis.com: web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... Steve,
Doesn't serializing the access to the Application object using the Lock and UnLock methods mean you have to accept a considerable performance hit ?
It seems to me that, although using the Application object gets the job done, it does so in a very inefficient way.
That's why I suggested adding a key in web.config, and retrieving *that* whenever needed. Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:u5**************@TK2MSFTNGP10.phx.gbl... > 'To store a variable: > Application.Lock() > Application("MyVar")="whatever" > Application.Unlock() > > 'to retrieve the variable: > Dim s as String = Application("MyVar").ToString() > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message> news:%2****************@TK2MSFTNGP09.phx.gbl... >> Hello, >> >> Can you tell me how to store the global variables in the >> Application >> Object? >> What should the code be and where should I place it? >> >> I am just starting with ASP.NET. >> >> Thanks, >> Miguel >> >> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >> news:St***@Orr.net: >>> With a web app, generally your global variables should be stored >>> in the>>> Application Object or Cache object. This way they are explicity >>> made >>> accessible to all code in your app. >>> >>> -- >>> I hope this helps, >>> Steve C. Orr, MCSD, MVP >>> http://Steve.Orr.net >>> >>> >>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>> message >>> >>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>> > Hello, >>> > >>> > I am working on an ASP.NET / VB page and I created a variable >>> > "query": >>> > >>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>> > Dim query as String = String.Empty >>> > ... >>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query>>> > End >>> > >>> > Sub >>> > >>> > I need "query" to be global and accessible everywhere. >>> > How can I do this? >>> > >>> > Thanks, >>> > Miguel >>> > >> > >
Hi, Miguel.
Kevin is right.
The web.config file's contents are loaded
into memory into the current AppDomain.
As soon as an Application starts, the configuration file
is loaded into memory, its contents are parsed and calls
are made to the relevant methods to register the objects
described in the file.
re: the change of value I do in my script on page_load doesn't change the default value?
No.
It only changes the variable instance's value.
The default value ( declared in web.config ) is unchanged.
You'd have to modify the web.config file itself,
in order to change the value of a variable set in it.
As soon as you save the changes to the new web.config,
the file will be reloaded and the changes registered.
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl... Hi Kevin,
I am not sure. If it is like that u mean that the change of value I do in my script on page_load doesn't change the default value?
Thanks, Miguel
"Kevin Spencer" <ks******@takempis.com> wrote in message news:ks******@takempis.com: web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... > Accessing the web.config is rather slow. > Application is faster because it's all in memory and doesn't need to access > the hard drive. (except maybe it's not fast when the server is under > heavy > load.) > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > > "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message > news:uB**************@TK2MSFTNGP11.phx.gbl... > > Steve, > > > > Doesn't serializing the access to the Application object > > using the Lock and UnLock methods mean you have to > > accept a considerable performance hit ? > > > > It seems to me that, although using the Application object > > gets the job done, it does so in a very inefficient way. > > > > That's why I suggested adding a key in web.config, > > and retrieving *that* whenever needed. > > > > > > > > Juan T. Llibre > > =========== > > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > > news:u5**************@TK2MSFTNGP10.phx.gbl... > >> 'To store a variable: > >> Application.Lock() > >> Application("MyVar")="whatever" > >> Application.Unlock() > >> > >> 'to retrieve the variable: > >> Dim s as String = Application("MyVar").ToString() > >> > >> -- > >> I hope this helps, > >> Steve C. Orr, MCSD, MVP > >> http://Steve.Orr.net > >> > >> > >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message > >> news:%2****************@TK2MSFTNGP09.phx.gbl... > >>> Hello, > >>> > >>> Can you tell me how to store the global variables in the > >>> Application > >>> Object? > >>> What should the code be and where should I place it? > >>> > >>> I am just starting with ASP.NET. > >>> > >>> Thanks, > >>> Miguel > >>> > >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > >>> news:St***@Orr.net: > >>>> With a web app, generally your global variables should be stored > >>>> in the > >>>> Application Object or Cache object. This way they are explicity > >>>> made > >>>> accessible to all code in your app. > >>>> > >>>> -- > >>>> I hope this helps, > >>>> Steve C. Orr, MCSD, MVP > >>>> http://Steve.Orr.net > >>>> > >>>> > >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in > >>>> message > >>>> > >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... > >>>> > Hello, > >>>> > > >>>> > I am working on an ASP.NET / VB page and I created a variable > >>>> > "query": > >>>> > > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) > >>>> > Dim query as String = String.Empty > >>>> > ... > >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query > >>>> > End > >>>> > > >>>> > Sub > >>>> > > >>>> > I need "query" to be global and accessible everywhere. > >>>> > How can I do this? > >>>> > > >>>> > Thanks, > >>>> > Miguel > >>>> > > >>> > >> > >> > > > > > >
Hola, Miguel,
Configuration values are read-only.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:Oz**************@TK2MSFTNGP10.phx.gbl... Hi Kevin,
I am not sure. If it is like that u mean that the change of value I do in my script on page_load doesn't change the default value?
Thanks, Miguel
"Kevin Spencer" <ks******@takempis.com> wrote in message news:ks******@takempis.com: web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the >>> Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored >>>> in the >>>> Application Object or Cache object. This way they are explicity >>>> made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
Hi,
This task it getting endless and really confusing :-)
What I need seems really simple...
On CommandText used in the dataset I want to use the SQL code include on
string queryDocuments which is build on page_load.
Sorry, but I am completely lost...once again.
Thanks,
Miguel Configuration values are read-only.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:Oz**************@TK2MSFTNGP10.phx.gbl... Hi Kevin,
I am not sure. If it is like that u mean that the change of value I do in my script on page_load doesn't change the default value?
Thanks, Miguel
"Kevin Spencer" <ks******@takempis.com> wrote in message news:ks******@takempis.com: web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... > Accessing the web.config is rather slow. > Application is faster because it's all in memory and doesn't need > to access > the hard drive. (except maybe it's not fast when the server is > under > heavy > load.) > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > > "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in > message > news:uB**************@TK2MSFTNGP11.phx.gbl... > > Steve, > > > > Doesn't serializing the access to the Application object > > using the Lock and UnLock methods mean you have to > > accept a considerable performance hit ? > > > > It seems to me that, although using the Application object > > gets the job done, it does so in a very inefficient way. > > > > That's why I suggested adding a key in web.config, > > and retrieving *that* whenever needed. > > > > > > > > Juan T. Llibre > > =========== > > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > > news:u5**************@TK2MSFTNGP10.phx.gbl... > >> 'To store a variable: > >> Application.Lock() > >> Application("MyVar")="whatever" > >> Application.Unlock() > >> > >> 'to retrieve the variable: > >> Dim s as String = Application("MyVar").ToString() > >> > >> -- > >> I hope this helps, > >> Steve C. Orr, MCSD, MVP > >> http://Steve.Orr.net > >> > >> > >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote > >> in message > >> news:%2****************@TK2MSFTNGP09.phx.gbl... > >>> Hello, > >>> > >>> Can you tell me how to store the global variables in the > >>> Application > >>> Object? > >>> What should the code be and where should I place it? > >>> > >>> I am just starting with ASP.NET. > >>> > >>> Thanks, > >>> Miguel > >>> > >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > >>> news:St***@Orr.net: > >>>> With a web app, generally your global variables should be > >>>> stored > >>>> in the > >>>> Application Object or Cache object. This way they are > >>>> explicity > >>>> made > >>>> accessible to all code in your app. > >>>> > >>>> -- > >>>> I hope this helps, > >>>> Steve C. Orr, MCSD, MVP > >>>> http://Steve.Orr.net > >>>> > >>>> > >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote > >>>> in > >>>> message > >>>> > >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... > >>>> > Hello, > >>>> > > >>>> > I am working on an ASP.NET / VB page and I created a > >>>> > variable > >>>> > "query": > >>>> > > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) > >>>> > Dim query as String = String.Empty > >>>> > ... > >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") > >>>> > & query > >>>> > End > >>>> > > >>>> > Sub > >>>> > > >>>> > I need "query" to be global and accessible everywhere. > >>>> > How can I do this? > >>>> > > >>>> > Thanks, > >>>> > Miguel > >>>> > > >>> > >> > >> > > > > > >
I used to think that but then I heard otherwise from somewhere...
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl... web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored in the >>>> Application Object or Cache object. This way they are explicity made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:Of*************@TK2MSFTNGP12.phx.gbl... I used to think that but then I heard otherwise from somewhere...
I thought it was loaded once per AppDomain? In fact, isn't this what the
configuration API does in general, regardless of whether it's ASP.NET or a
Windows Service?
I once tried to get a Windows Service to re-read its config file by using
pause and continue, and it didn't work. I came to believe that I'd need to
start a new AppDomain in order to get a fresh read of the config file. I no
longer recall where I heard that the new AppDomain would do the trick, and
didn't try it out.
John Saunders -- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message news:Oh**************@TK2MSFTNGP10.phx.gbl... web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored in the >>>> Application Object or Cache object. This way they are explicity >>>> made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
re: I used to think that but then I heard otherwise from somewhere.
Please tell whomever told you that, that he/she is wrong.
See http://msdn.microsoft.com/library/de...ingArchch3.asp
"A good example of this is the way the .NET Framework
handles its configuration files (Web.config and Machine.config),
which are loaded into memory as soon as they are updated,
causing the application to use the new configuration data
as soon as it is available."
HTH...
Juan T. Llibre
===========
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:Of*************@TK2MSFTNGP12.phx.gbl...I used to think that but then I heard otherwise from somewhere...
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message news:Oh**************@TK2MSFTNGP10.phx.gbl... web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored in the >>>> Application Object or Cache object. This way they are explicity >>>> made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
Steve was misled.
See http://msdn.microsoft.com/library/de...ingArchch3.asp
"A good example of this is the way the .NET Framework
handles its configuration files (Web.config and Machine.config),
which are loaded into memory as soon as they are updated,
causing the application to use the new configuration data
as soon as it is available."
Juan T. Llibre
===========
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl... "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:Of*************@TK2MSFTNGP12.phx.gbl...I used to think that but then I heard otherwise from somewhere...
I thought it was loaded once per AppDomain? In fact, isn't this what the configuration API does in general, regardless of whether it's ASP.NET or a Windows Service?
I once tried to get a Windows Service to re-read its config file by using pause and continue, and it didn't work. I came to believe that I'd need to start a new AppDomain in order to get a fresh read of the config file. I no longer recall where I heard that the new AppDomain would do the trick, and didn't try it out.
John Saunders -- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message news:Oh**************@TK2MSFTNGP10.phx.gbl... web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the >>> Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored >>>> in the >>>> Application Object or Cache object. This way they are explicity >>>> made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:O7****************@tk2msftngp13.phx.gbl... Steve was misled.
See http://msdn.microsoft.com/library/de...ingArchch3.asp
"A good example of this is the way the .NET Framework handles its configuration files (Web.config and Machine.config), which are loaded into memory as soon as they are updated, causing the application to use the new configuration data as soon as it is available."
This talks about web.config and machine.config. I know that in the case of
web.config, the reason that the changes are loaded as soon as they are
available is that the application is restarted in a new AppDomain. This is
consistent with the idea that the configuration information loads once per
AppDomain, as though there were a single, static instance of the
configuration.
John Saunders
Absolutely.
Saving either web.config or global.asax files
causes the restart of the application into a new AppDomain.
Saving the machine.config file will cause
a restart of *all* ASP.NET applications
on the server involved.
And, yes, the configuration information
loads once per AppDomain
Juan T. Llibre
===========
"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:uZ****************@TK2MSFTNGP11.phx.gbl... "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:O7****************@tk2msftngp13.phx.gbl... Steve was misled.
See http://msdn.microsoft.com/library/de...ingArchch3.asp
"A good example of this is the way the .NET Framework handles its configuration files (Web.config and Machine.config), which are loaded into memory as soon as they are updated, causing the application to use the new configuration data as soon as it is available."
This talks about web.config and machine.config. I know that in the case of web.config, the reason that the changes are loaded as soon as they are available is that the application is restarted in a new AppDomain. This is consistent with the idea that the configuration information loads once per AppDomain, as though there were a single, static instance of the configuration.
John Saunders
Hi,
What a discussion this became.
So when I change the value of the variable in my script it doesn't
change the value in web.config file and so the global value is still the
same?
This is what it seems to be happening.
Anyway, maybe is there a way to solve this or maybe the solution is
completely different from using web.config?
Sorry, by I am starting with ASP.NET and I am working on this for 2
weeks and this is the last detail to end this project.
Thanks,
Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:no***********@nowhere.com: re:I used to think that but then I heard otherwise from somewhere.
Please tell whomever told you that, that he/she is wrong.
See
http://msdn.microsoft.com/library/de...us/dnbda/html/ CachingArchch3.asp
"A good example of this is the way the .NET Framework handles its configuration files (Web.config and Machine.config), which are loaded into memory as soon as they are updated, causing the application to use the new configuration data as soon as it is available."
HTH... Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:Of*************@TK2MSFTNGP12.phx.gbl...I used to think that but then I heard otherwise from somewhere...
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message news:Oh**************@TK2MSFTNGP10.phx.gbl... web.config is loaded into memory when the app starts, isn't that correct?
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:e9**************@TK2MSFTNGP10.phx.gbl... Accessing the web.config is rather slow. Application is faster because it's all in memory and doesn't need to access the hard drive. (except maybe it's not fast when the server is under
heavy load.)
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:uB**************@TK2MSFTNGP11.phx.gbl... > Steve, > > Doesn't serializing the access to the Application object > using the Lock and UnLock methods mean you have to > accept a considerable performance hit ? > > It seems to me that, although using the Application object > gets the job done, it does so in a very inefficient way. > > That's why I suggested adding a key in web.config, > and retrieving *that* whenever needed. > > > > Juan T. Llibre > =========== > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:u5**************@TK2MSFTNGP10.phx.gbl... >> 'To store a variable: >> Application.Lock() >> Application("MyVar")="whatever" >> Application.Unlock() >> >> 'to retrieve the variable: >> Dim s as String = Application("MyVar").ToString() >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> Hello, >>> >>> Can you tell me how to store the global variables in the >>> Application >>> Object? >>> What should the code be and where should I place it? >>> >>> I am just starting with ASP.NET. >>> >>> Thanks, >>> Miguel >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> news:St***@Orr.net: >>>> With a web app, generally your global variables should be stored >>>> in the >>>> Application Object or Cache object. This way they are explicity >>>> >>>> made >>>> accessible to all code in your app. >>>> >>>> -- >>>> I hope this helps, >>>> Steve C. Orr, MCSD, MVP >>>> http://Steve.Orr.net >>>> >>>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote >>>> in >>>> message >>>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>>> > Hello, >>>> > >>>> > I am working on an ASP.NET / VB page and I created a variable >>>> > "query": >>>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>>> > Dim query as String = String.Empty >>>> > ... >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") >>>> > & query >>>> > End >>>> > >>>> > Sub >>>> > >>>> > I need "query" to be global and accessible everywhere. >>>> > How can I do this? >>>> > >>>> > Thanks, >>>> > Miguel >>>> > >>> >> >> > >
Use Application Cache.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:eX**************@TK2MSFTNGP12.phx.gbl... Hi,
What a discussion this became. So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same?
This is what it seems to be happening.
Anyway, maybe is there a way to solve this or maybe the solution is completely different from using web.config?
Sorry, by I am starting with ASP.NET and I am working on this for 2 weeks and this is the last detail to end this project.
Thanks, Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: re:I used to think that but then I heard otherwise from somewhere.
Please tell whomever told you that, that he/she is wrong.
See
http://msdn.microsoft.com/library/de...us/dnbda/html/ CachingArchch3.asp
"A good example of this is the way the .NET Framework handles its configuration files (Web.config and Machine.config), which are loaded into memory as soon as they are updated, causing the application to use the new configuration data as soon as it is available."
HTH... Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:Of*************@TK2MSFTNGP12.phx.gbl...I used to think that but then I heard otherwise from somewhere...
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"Kevin Spencer" <ks******@takempis.com> wrote in message news:Oh**************@TK2MSFTNGP10.phx.gbl... > web.config is loaded into memory when the app starts, isn't that > correct? > > -- > HTH, > Kevin Spencer > .Net Developer > Microsoft MVP > Neither a follower > nor a lender be. > > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message > news:e9**************@TK2MSFTNGP10.phx.gbl... >> Accessing the web.config is rather slow. >> Application is faster because it's all in memory and doesn't need to > access >> the hard drive. (except maybe it's not fast when the server is under >> >> heavy >> load.) >> >> -- >> I hope this helps, >> Steve C. Orr, MCSD, MVP >> http://Steve.Orr.net >> >> >> >> "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message >> news:uB**************@TK2MSFTNGP11.phx.gbl... >> > Steve, >> > >> > Doesn't serializing the access to the Application object >> > using the Lock and UnLock methods mean you have to >> > accept a considerable performance hit ? >> > >> > It seems to me that, although using the Application object >> > gets the job done, it does so in a very inefficient way. >> > >> > That's why I suggested adding a key in web.config, >> > and retrieving *that* whenever needed. >> > >> > >> > >> > Juan T. Llibre >> > =========== >> > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >> > news:u5**************@TK2MSFTNGP10.phx.gbl... >> >> 'To store a variable: >> >> Application.Lock() >> >> Application("MyVar")="whatever" >> >> Application.Unlock() >> >> >> >> 'to retrieve the variable: >> >> Dim s as String = Application("MyVar").ToString() >> >> >> >> -- >> >> I hope this helps, >> >> Steve C. Orr, MCSD, MVP >> >> http://Steve.Orr.net >> >> >> >> >> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in > message >> >> news:%2****************@TK2MSFTNGP09.phx.gbl... >> >>> Hello, >> >>> >> >>> Can you tell me how to store the global variables in the >> >>> Application >> >>> Object? >> >>> What should the code be and where should I place it? >> >>> >> >>> I am just starting with ASP.NET. >> >>> >> >>> Thanks, >> >>> Miguel >> >>> >> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >> >>> news:St***@Orr.net: >> >>>> With a web app, generally your global variables should be
stored>> >>>> in > the >> >>>> Application Object or Cache object. This way they are explicity >> >>>> >> >>>> made >> >>>> accessible to all code in your app. >> >>>> >> >>>> -- >> >>>> I hope this helps, >> >>>> Steve C. Orr, MCSD, MVP >> >>>> http://Steve.Orr.net >> >>>> >> >>>> >> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote >> >>>> in >> >>>> message >> >>>> >> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >> >>>> > Hello, >> >>>> > >> >>>> > I am working on an ASP.NET / VB page and I created a variable >> >>>> > "query": >> >>>> > >> >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >> >>>> > Dim query as String = String.Empty >> >>>> > ... >> >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") >> >>>> > & > query >> >>>> > End >> >>>> > >> >>>> > Sub >> >>>> > >> >>>> > I need "query" to be global and accessible everywhere. >> >>>> > How can I do this? >> >>>> > >> >>>> > Thanks, >> >>>> > Miguel >> >>>> > >> >>> >> >> >> >> >> > >> > >> >> > >
re: What a discussion this became.
It hasn't been a "nasty" discussion, though... :-)
It's great when we can exchange differing points of view,
because then there's a chance for the truth to emerge.
re: So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same?
I thought we had covered that situation.
Here's the quote from my message to you :
---------------
You are retrieving/setting the query's value twice.
Once with:
CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with
Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrieve it
sets the value for the CommandText permanently ?
Why are you retrieving that value twice,
and assigning the same value to two different variables ?
( CommandText and queryDocuments )
If you have a permanent value for CommandText,
then nothing you do with "queryDocuments", later,
will affect the value for "CommandText".
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... Hi, What a discussion this became. So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same? This is what it seems to be happening.
Let me expand on that. You can store an initial value in a config file, and
when the app starts, assign that value to a Cache variable. After that, you
use only the Cache variable, which you may change at will.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl... Use Application Cache.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Neither a follower nor a lender be.
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... Hi,
What a discussion this became. So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same?
This is what it seems to be happening.
Anyway, maybe is there a way to solve this or maybe the solution is completely different from using web.config?
Sorry, by I am starting with ASP.NET and I am working on this for 2 weeks and this is the last detail to end this project.
Thanks, Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: re: >I used to think that but then I heard otherwise from somewhere.
Please tell whomever told you that, that he/she is wrong.
See
http://msdn.microsoft.com/library/de...us/dnbda/html/ CachingArchch3.asp
"A good example of this is the way the .NET Framework handles its configuration files (Web.config and Machine.config), which are loaded into memory as soon as they are updated, causing the application to use the new configuration data as soon as it is available."
HTH... Juan T. Llibre =========== "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:Of*************@TK2MSFTNGP12.phx.gbl... >I used to think that but then I heard otherwise from somewhere... > > -- > I hope this helps, > Steve C. Orr, MCSD, MVP > http://Steve.Orr.net > > > "Kevin Spencer" <ks******@takempis.com> wrote in message > news:Oh**************@TK2MSFTNGP10.phx.gbl... >> web.config is loaded into memory when the app starts, isn't that >> correct? >> >> -- >> HTH, >> Kevin Spencer >> .Net Developer >> Microsoft MVP >> Neither a follower >> nor a lender be. >> >> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >> news:e9**************@TK2MSFTNGP10.phx.gbl... >>> Accessing the web.config is rather slow. >>> Application is faster because it's all in memory and doesn't need
to >> access >>> the hard drive. (except maybe it's not fast when the server is
under >>> >>> heavy >>> load.) >>> >>> -- >>> I hope this helps, >>> Steve C. Orr, MCSD, MVP >>> http://Steve.Orr.net >>> >>> >>> >>> "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in
message >>> news:uB**************@TK2MSFTNGP11.phx.gbl... >>> > Steve, >>> > >>> > Doesn't serializing the access to the Application object >>> > using the Lock and UnLock methods mean you have to >>> > accept a considerable performance hit ? >>> > >>> > It seems to me that, although using the Application object >>> > gets the job done, it does so in a very inefficient way. >>> > >>> > That's why I suggested adding a key in web.config, >>> > and retrieving *that* whenever needed. >>> > >>> > >>> > >>> > Juan T. Llibre >>> > =========== >>> > "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> > news:u5**************@TK2MSFTNGP10.phx.gbl... >>> >> 'To store a variable: >>> >> Application.Lock() >>> >> Application("MyVar")="whatever" >>> >> Application.Unlock() >>> >> >>> >> 'to retrieve the variable: >>> >> Dim s as String = Application("MyVar").ToString() >>> >> >>> >> -- >>> >> I hope this helps, >>> >> Steve C. Orr, MCSD, MVP >>> >> http://Steve.Orr.net >>> >> >>> >> >>> >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote
in >> message >>> >> news:%2****************@TK2MSFTNGP09.phx.gbl... >>> >>> Hello, >>> >>> >>> >>> Can you tell me how to store the global variables in the >>> >>> Application >>> >>> Object? >>> >>> What should the code be and where should I place it? >>> >>> >>> >>> I am just starting with ASP.NET. >>> >>> >>> >>> Thanks, >>> >>> Miguel >>> >>> >>> >>> "Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message >>> >>> news:St***@Orr.net: >>> >>>> With a web app, generally your global variables should be stored >>> >>>> in >> the >>> >>>> Application Object or Cache object. This way they are
explicity >>> >>>> >>> >>>> made >>> >>>> accessible to all code in your app. >>> >>>> >>> >>>> -- >>> >>>> I hope this helps, >>> >>>> Steve C. Orr, MCSD, MVP >>> >>>> http://Steve.Orr.net >>> >>>> >>> >>>> >>> >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote >>> >>>> in >>> >>>> message >>> >>>> >>> >>>> news:OP**************@TK2MSFTNGP09.phx.gbl... >>> >>>> > Hello, >>> >>>> > >>> >>>> > I am working on an ASP.NET / VB page and I created a
variable >>> >>>> > "query": >>> >>>> > >>> >>>> > Sub Page_Load(sender As Object, e As System.EventArgs) >>> >>>> > Dim query as String = String.Empty >>> >>>> > ... >>> >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE
") >>> >>>> > & >> query >>> >>>> > End >>> >>>> > >>> >>>> > Sub >>> >>>> > >>> >>>> > I need "query" to be global and accessible everywhere. >>> >>>> > How can I do this? >>> >>>> > >>> >>>> > Thanks, >>> >>>> > Miguel >>> >>>> > >>> >>> >>> >> >>> >> >>> > >>> > >>> >>> >> >> > >
Hi,
Yes it has been a great discussion. I have been learning a lot. :-)
As I told you I am new to ASP.NET and at last post I got completely
lost.
Please focus on the problem I have in hands. :-)
It's just that receiving all kind of general ideas is great because I
can learn but after a while I get lost and I try all kind of things but
I never get this right and working.
Here is my entire code. Maybe it's easier to get a view of it.
<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"
Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,culture=neutral"
%>
<MM:DataSet
id="dsDocuments"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING_conBonsAlunos")
%>'
DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABASETYPE_conBonsAlunos")
%>'
CommandText='<%#
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
%>'
Debug="true" </MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import NameSpace="System.Text" %>
<script runat="server">
Sub Page_Load(sender As Object, e As System.EventArgs)
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("queryDocuments"))
Dim queryDocuments As String =
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
If Request.QueryString("pesquisar") Is Nothing Then
queryDocuments = "SELECT * FROM dbo.documents"
Else
queryDocuments = ""
Dim keywords as string()
keywords = Request.QueryString("pesquisar").Split(CChar(" "))
Dim i As Int32
For i = 0 To keywords.Length
queryDocuments += String.Format("CONTAINS (*, '{0}') ",
keywords(i))
If i + 1 = keywords.Length Then
i = keywords.Length
Exit For
End If
queryDocuments += " AND "
Next
queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE
") & queryDocuments
End If
End Sub
Sub searchDocuments(sender As Object, e As System.EventArgs)
Server.Transfer("material-didactico.aspx?pesquisar=" &
Request.Form("pesquisar_keywords"))
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
..
..
..
WEB.CONFIG:
<appSettings>
<add key="MM_CONNECTION_HANDLER_conBonsAlunos" value="sqlserver.htm"
/>
<add key="MM_CONNECTION_STRING_conBonsAlunos" value="Persist Security
Info=False;Data Source=(local);Initial Catalog=dbBonsAlunos;User
ID=sa;Password=" />
<add key="MM_CONNECTION_DATABASETYPE_conBonsAlunos" value="SQLServer"
/>
<add key="MM_CONNECTION_SCHEMA_conBonsAlunos" value="" />
<add key="MM_CONNECTION_CATALOG_conBonsAlunos" value="" />
<add key="queryDocuments" value="SELECT * FROM dbo.documents"/>
</appSettings>
Thanks once again,
Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message
news:no***********@nowhere.com: re: What a discussion this became.
It hasn't been a "nasty" discussion, though... :-) It's great when we can exchange differing points of view, because then there's a chance for the truth to emerge.
re: So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same?
I thought we had covered that situation.
Here's the quote from my message to you : ---------------
You are retrieving/setting the query's value twice.
Once with: CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrieve it sets the value for the CommandText permanently ?
Why are you retrieving that value twice, and assigning the same value to two different variables ? ( CommandText and queryDocuments )
If you have a permanent value for CommandText, then nothing you do with "queryDocuments", later, will affect the value for "CommandText".
Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... Hi,
What a discussion this became. So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the
same?
This is what it seems to be happening.
As near as I can figure it out, what's happening
is that you're binding the MM datagrid CommandText
variable to the web.config queryDocuments key.
The CommandText never gets updated, because when you later
process the queryDocuments variable, that does not change the
value of the web.config appSetting to which the MM Datagrid's
CommandText was bound earlier.
You need to pass the *new* contents of the queryDocuments
variable to the MM Datagrid, after you process the changes to it.
I don't know enough about how the MM Datagrid takes variables
so that I could recommend you a course of action.
If you can pass the queryDocuments variable to the MM Datagrid
*after* you process that variable, that should work OK.
You might have to ask in a MacroMedia ng to find that out.
i.e., if you could place the MM Datagrid *after* you process the
queryDocuments variable, and pass the new value with something like :
CommandText='<%# queryDocuments %>'
then, I'm pretty sure it'd work.
But, like I said, I don't know enough about
the MM Datagrid to tell you if that's possible.
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Hi,
Yes it has been a great discussion. I have been learning a lot. :-)
As I told you I am new to ASP.NET and at last post I got completely lost.
Please focus on the problem I have in hands. :-) It's just that receiving all kind of general ideas is great because I can learn but after a while I get lost and I try all kind of things but I never get this right and working.
Here is my entire code. Maybe it's easier to get a view of it.
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,culture=neutral" %> <MM:DataSet id="dsDocuments" runat="Server" IsStoredProcedure="false" ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING_conBonsAlunos") %>' DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABASETYPE_conBonsAlunos") %>' CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>' Debug="true"</MM:DataSet> <MM:PageBind runat="server" PostBackBind="true" /> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@ Import NameSpace="System.Text" %>
<script runat="server">
Sub Page_Load(sender As Object, e As System.EventArgs)
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("queryDocuments")) Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") If Request.QueryString("pesquisar") Is Nothing Then queryDocuments = "SELECT * FROM dbo.documents" Else queryDocuments = "" Dim keywords as string() keywords = Request.QueryString("pesquisar").Split(CChar(" ")) Dim i As Int32 For i = 0 To keywords.Length queryDocuments += String.Format("CONTAINS (*, '{0}') ", keywords(i)) If i + 1 = keywords.Length Then i = keywords.Length Exit For End If queryDocuments += " AND " Next queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE ") & queryDocuments End If End Sub
Sub searchDocuments(sender As Object, e As System.EventArgs) Server.Transfer("material-didactico.aspx?pesquisar=" & Request.Form("pesquisar_keywords")) End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml"> . . .
WEB.CONFIG:
<appSettings> <add key="MM_CONNECTION_HANDLER_conBonsAlunos" value="sqlserver.htm" /> <add key="MM_CONNECTION_STRING_conBonsAlunos" value="Persist Security Info=False;Data Source=(local);Initial Catalog=dbBonsAlunos;User ID=sa;Password=" /> <add key="MM_CONNECTION_DATABASETYPE_conBonsAlunos" value="SQLServer" /> <add key="MM_CONNECTION_SCHEMA_conBonsAlunos" value="" /> <add key="MM_CONNECTION_CATALOG_conBonsAlunos" value="" /> <add key="queryDocuments" value="SELECT * FROM dbo.documents"/> </appSettings>
Thanks once again, Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: re: > What a discussion this became.
It hasn't been a "nasty" discussion, though... :-) It's great when we can exchange differing points of view, because then there's a chance for the truth to emerge.
re: > So when I change the value of the variable in my script it doesn't > change the value in web.config file and so the global value is still > the > same?
I thought we had covered that situation.
Here's the quote from my message to you : ---------------
You are retrieving/setting the query's value twice.
Once with: CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrieve it sets the value for the CommandText permanently ?
Why are you retrieving that value twice, and assigning the same value to two different variables ? ( CommandText and queryDocuments )
If you have a permanent value for CommandText, then nothing you do with "queryDocuments", later, will affect the value for "CommandText".
Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... > Hi, > > What a discussion this became. > So when I change the value of the variable in my script it doesn't > change the value in web.config file and so the global value is still > the > > same? > > This is what it seems to be happening.
Hi...
from you post what i understood is..
you have a value (some qrystring) that will be changed by the user..after
changing ..the changed value should be used...is it ?
if my point is correct.....you can maintain the important values(dynamic
values) with in viewstate..
-raj
"Miguel Dias Moura" wrote: Hi,
Yes it has been a great discussion. I have been learning a lot. :-)
As I told you I am new to ASP.NET and at last post I got completely lost.
Please focus on the problem I have in hands. :-) It's just that receiving all kind of general ideas is great because I can learn but after a while I get lost and I try all kind of things but I never get this right and working.
Here is my entire code. Maybe it's easier to get a view of it.
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,culture=neutral" %> <MM:DataSet id="dsDocuments" runat="Server" IsStoredProcedure="false" ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING_conBonsAlunos") %>' DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABASETYPE_conBonsAlunos") %>' CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>' Debug="true"</MM:DataSet> <MM:PageBind runat="server" PostBackBind="true" /> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@ Import NameSpace="System.Text" %>
<script runat="server">
Sub Page_Load(sender As Object, e As System.EventArgs)
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("queryDocuments")) Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") If Request.QueryString("pesquisar") Is Nothing Then queryDocuments = "SELECT * FROM dbo.documents" Else queryDocuments = "" Dim keywords as string() keywords = Request.QueryString("pesquisar").Split(CChar(" ")) Dim i As Int32 For i = 0 To keywords.Length queryDocuments += String.Format("CONTAINS (*, '{0}') ", keywords(i)) If i + 1 = keywords.Length Then i = keywords.Length Exit For End If queryDocuments += " AND " Next queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE ") & queryDocuments End If End Sub
Sub searchDocuments(sender As Object, e As System.EventArgs) Server.Transfer("material-didactico.aspx?pesquisar=" & Request.Form("pesquisar_keywords")) End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml"> .. .. ..
WEB.CONFIG:
<appSettings> <add key="MM_CONNECTION_HANDLER_conBonsAlunos" value="sqlserver.htm" /> <add key="MM_CONNECTION_STRING_conBonsAlunos" value="Persist Security Info=False;Data Source=(local);Initial Catalog=dbBonsAlunos;User ID=sa;Password=" /> <add key="MM_CONNECTION_DATABASETYPE_conBonsAlunos" value="SQLServer" /> <add key="MM_CONNECTION_SCHEMA_conBonsAlunos" value="" /> <add key="MM_CONNECTION_CATALOG_conBonsAlunos" value="" /> <add key="queryDocuments" value="SELECT * FROM dbo.documents"/> </appSettings>
Thanks once again, Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: re: What a discussion this became.
It hasn't been a "nasty" discussion, though... :-) It's great when we can exchange differing points of view, because then there's a chance for the truth to emerge.
re: So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the same?
I thought we had covered that situation.
Here's the quote from my message to you : ---------------
You are retrieving/setting the query's value twice.
Once with: CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with Dim queryDocuments As String = System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrieve it sets the value for the CommandText permanently ?
Why are you retrieving that value twice, and assigning the same value to two different variables ? ( CommandText and queryDocuments )
If you have a permanent value for CommandText, then nothing you do with "queryDocuments", later, will affect the value for "CommandText".
Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... Hi,
What a discussion this became. So when I change the value of the variable in my script it doesn't change the value in web.config file and so the global value is still the
same?
This is what it seems to be happening.
People,
Sometimes the solution is simpler then we think.
I just used this:
<script runat="server"> Dim queryDocuments as String = String.Empty <<<
Sub Page_Load(sender As Object, e As System.EventArgs)
If Request.QueryString("pesquisar") Is Nothing Then
queryDocuments = "SELECT * FROM dbo.documents"
Else
...
Now queryDocuments is available everywhere in the page and I can use:
CommandText='<%# queryDocuments %>'
It's solved.
Thanks to Everybody,
Miguel
"rajamanickam" <ra**********@discussions.microsoft.com> wrote in message
news:ra**********@discussions.microsoft.com: Hi...
from you post what i understood is.. you have a value (some qrystring) that will be changed by the user..after
changing ..the changed value should be used...is it ?
if my point is correct.....you can maintain the important values(dynamic
values) with in viewstate..
-raj
"Miguel Dias Moura" wrote:
Hi,
Yes it has been a great discussion. I have been learning a lot. :-)
As I told you I am new to ASP.NET and at last post I got completely lost.
Please focus on the problem I have in hands. :-) It's just that receiving all kind of general ideas is great because I can learn but after a while I get lost and I try all kind of things but
I never get this right and working.
Here is my entire code. Maybe it's easier to get a view of it.
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"
Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,c ulture=neutral" %> <MM:DataSet id="dsDocuments" runat="Server" IsStoredProcedure="false" ConnectionString='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING _conBonsAlunos") %>' DatabaseType='<%#
System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABA SETYPE_conBonsAlunos") %>' CommandText='<%# System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
%>' Debug="true"</MM:DataSet> <MM:PageBind runat="server" PostBackBind="true" /> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@ Import NameSpace="System.Text" %>
<script runat="server">
Sub Page_Load(sender As Object, e As System.EventArgs)
Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("query Documents")) Dim queryDocuments As String =
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") If Request.QueryString("pesquisar") Is Nothing Then queryDocuments = "SELECT * FROM dbo.documents" Else queryDocuments = "" Dim keywords as string() keywords = Request.QueryString("pesquisar").Split(CChar(" ")) Dim i As Int32 For i = 0 To keywords.Length queryDocuments += String.Format("CONTAINS (*, '{0}') ", keywords(i)) If i + 1 = keywords.Length Then i = keywords.Length Exit For End If queryDocuments += " AND " Next queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE
") & queryDocuments End If End Sub
Sub searchDocuments(sender As Object, e As System.EventArgs) Server.Transfer("material-didactico.aspx?pesquisar=" & Request.Form("pesquisar_keywords")) End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml"> .. .. ..
WEB.CONFIG:
<appSettings> <add key="MM_CONNECTION_HANDLER_conBonsAlunos" value="sqlserver.htm"
/> <add key="MM_CONNECTION_STRING_conBonsAlunos" value="Persist Security
Info=False;Data Source=(local);Initial Catalog=dbBonsAlunos;User ID=sa;Password=" /> <add key="MM_CONNECTION_DATABASETYPE_conBonsAlunos" value="SQLServer"
/> <add key="MM_CONNECTION_SCHEMA_conBonsAlunos" value="" /> <add key="MM_CONNECTION_CATALOG_conBonsAlunos" value="" /> <add key="queryDocuments" value="SELECT * FROM dbo.documents"/> </appSettings>
Thanks once again, Miguel
"Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message news:no***********@nowhere.com: re: > What a discussion this became.
It hasn't been a "nasty" discussion, though... :-) It's great when we can exchange differing points of view, because then there's a chance for the truth to emerge.
re: > So when I change the value of the variable in my script it doesn't > change the value in web.config file and so the global value is still > the > same?
I thought we had covered that situation.
Here's the quote from my message to you : ---------------
You are retrieving/setting the query's value twice.
Once with: CommandText='<%#
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") %>'
and you retrieve it again with Dim queryDocuments As String =
System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments")
Is it possible that the first time you retrieve it sets the value for the CommandText permanently ?
Why are you retrieving that value twice, and assigning the same value to two different variables ? ( CommandText and queryDocuments )
If you have a permanent value for CommandText, then nothing you do with "queryDocuments", later, will affect the value for "CommandText".
Juan T. Llibre =========== "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message news:eX**************@TK2MSFTNGP12.phx.gbl... > Hi, > > What a discussion this became. > So when I change the value of the variable in my script it doesn't > change the value in web.config file and so the global value is still > the > > same? > > This is what it seems to be happening.
I'm happy to see that the suggestion to use CommandText='<%# queryDocuments %>'
worked, Miguel.
Congratulations on figuring out that Dim queryDocuments as String = String.Empty
was needed in order to be able to use it.
Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... People,
Sometimes the solution is simpler then we think.
I just used this:
<script runat="server">
>>> Dim queryDocuments as String = String.Empty <<<
Sub Page_Load(sender As Object, e As System.EventArgs) If Request.QueryString("pesquisar") Is Nothing Then queryDocuments = "SELECT * FROM dbo.documents" Else ...
Now queryDocuments is available everywhere in the page and I can use: CommandText='<%# queryDocuments %>'
It's solved.
Thanks to Everybody, Miguel
"rajamanickam" <ra**********@discussions.microsoft.com> wrote in message news:ra**********@discussions.microsoft.com: Hi...
from you post what i understood is.. you have a value (some qrystring) that will be changed by the user..after
changing ..the changed value should be used...is it ?
if my point is correct.....you can maintain the important values(dynamic
values) with in viewstate..
-raj
"Miguel Dias Moura" wrote:
> Hi, > > Yes it has been a great discussion. I have been learning a lot. :-) > > As I told you I am new to ASP.NET and at last post I got completely > lost. > > Please focus on the problem I have in hands. :-) > It's just that receiving all kind of general ideas is great because I > can learn but after a while I get lost and I try all kind of things but > > I never get this right and working. > > Here is my entire code. Maybe it's easier to get a view of it. > > <%@ Page Language="VB" ContentType="text/html" > ResponseEncoding="iso-8859-1" %> > <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" > > Assembly="DreamweaverCtrls,version=1.0.0.0,publicK eyToken=836f606ede05d46a,c > ulture=neutral" > %> > <MM:DataSet > id="dsDocuments" > runat="Server" > IsStoredProcedure="false" > ConnectionString='<%# > > System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_STRING > _conBonsAlunos") > %>' > DatabaseType='<%# > > System.Configuration.ConfigurationSettings.AppSett ings("MM_CONNECTION_DATABA > SETYPE_conBonsAlunos") > %>' > CommandText='<%# > System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") > > %>' > Debug="true" > ></MM:DataSet> > <MM:PageBind runat="server" PostBackBind="true" /> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <%@ Import NameSpace="System.Text" %> > > <script runat="server"> > > Sub Page_Load(sender As Object, e As System.EventArgs) > > > Response.Write(System.Configuration.ConfigurationS ettings.AppSettings("query > Documents")) > Dim queryDocuments As String = > > System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") > If Request.QueryString("pesquisar") Is Nothing Then queryDocuments > = "SELECT * FROM dbo.documents" > Else queryDocuments = "" > Dim keywords as string() > keywords = Request.QueryString("pesquisar").Split(CChar(" ")) > Dim i As Int32 > For i = 0 To keywords.Length > queryDocuments += String.Format("CONTAINS (*, '{0}') ", > keywords(i)) > If i + 1 = keywords.Length Then > i = keywords.Length > Exit For > End If > queryDocuments += " AND " Next > queryDocuments = String.Format("SELECT * FROM dbo.documents WHERE > > ") & queryDocuments > End If End Sub > > Sub searchDocuments(sender As Object, e As System.EventArgs) > Server.Transfer("material-didactico.aspx?pesquisar=" & > Request.Form("pesquisar_keywords")) > End Sub > > </script> > > <html xmlns="http://www.w3.org/1999/xhtml"> > .. > .. > .. > > WEB.CONFIG: > > <appSettings> > <add key="MM_CONNECTION_HANDLER_conBonsAlunos" value="sqlserver.htm" > > /> > <add key="MM_CONNECTION_STRING_conBonsAlunos" value="Persist Security > > Info=False;Data Source=(local);Initial Catalog=dbBonsAlunos;User > ID=sa;Password=" /> > <add key="MM_CONNECTION_DATABASETYPE_conBonsAlunos" value="SQLServer" > > /> > <add key="MM_CONNECTION_SCHEMA_conBonsAlunos" value="" /> > <add key="MM_CONNECTION_CATALOG_conBonsAlunos" value="" /> <add > key="queryDocuments" value="SELECT * FROM dbo.documents"/> > </appSettings> > > Thanks once again, > Miguel > > > "Juan T. Llibre [MVP]" <no***********@nowhere.com> wrote in message > news:no***********@nowhere.com: > > re: > > > What a discussion this became. > > > > It hasn't been a "nasty" discussion, though... :-) > > It's great when we can exchange differing points of view, > > because then there's a chance for the truth to emerge. > > > > re: > > > So when I change the value of the variable in my script it doesn't > > > change the value in web.config file and so the global value is > > > still > > > the > > > same? > > > > I thought we had covered that situation. > > > > Here's the quote from my message to you : > > --------------- > > > > You are retrieving/setting the query's value twice. > > > > Once with: > > CommandText='<%# > > > > System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") > > %>' > > > > and you retrieve it again with > > Dim queryDocuments As String = > > > > System.Configuration.ConfigurationSettings.AppSett ings("queryDocuments") > > > > Is it possible that the first time you retrieve it > > sets the value for the CommandText permanently ? > > > > Why are you retrieving that value twice, > > and assigning the same value to two different variables ? > > ( CommandText and queryDocuments ) > > > > > > If you have a permanent value for CommandText, > > then nothing you do with "queryDocuments", later, > > will affect the value for "CommandText". > > > > > > > > > > Juan T. Llibre > > =========== > > "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in > > message > > news:eX**************@TK2MSFTNGP12.phx.gbl... > > > Hi, > > > > > > What a discussion this became. > > > So when I change the value of the variable in my script it doesn't > > > change the value in web.config file and so the global value is > > > still > > > the > > > > > > same? > > > > > > This is what it seems to be happening. > >
You can have a base page class that all of your pages inherit from and
retrieve all of your variables from the web.config file. This eliminates
using Application and Cache variables which are (InProc)ess variables. They
will be available to all of your pages. You may also want to create a base
user control from which all your user controls can inherit from. Finally, in
web.config, you can modify the <pages> node to set the base page and user
control that all your pages will inherit from.
"Miguel Dias Moura" wrote: Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
why don't you use some application object in ASP.NET for accessing that
variable globally.
Regards
"Suman Chakrabarti" <Suman Ch*********@discussions.microsoft.com> wrote in
message news:E9**********************************@microsof t.com... You can have a base page class that all of your pages inherit from and retrieve all of your variables from the web.config file. This eliminates using Application and Cache variables which are (InProc)ess variables.
They will be available to all of your pages. You may also want to create a
base user control from which all your user controls can inherit from. Finally,
in web.config, you can modify the <pages> node to set the base page and user control that all your pages will inherit from.
"Miguel Dias Moura" wrote:
Hello,
I am working on an ASP.NET / VB page and I created a variable "query":
Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query = String.Format("SELECT * FROM dbo.documents WHERE ") & query End Sub
I need "query" to be global and accessible everywhere. How can I do this?
Thanks, Miguel
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
5 posts
views
Thread by NotGiven |
last post: by
|
10 posts
views
Thread by Andy Fish |
last post: by
|
6 posts
views
Thread by rick |
last post: by
|
6 posts
views
Thread by Joe Molloy |
last post: by
|
23 posts
views
Thread by Russ Chinoy |
last post: by
|
16 posts
views
Thread by didier.doussaud |
last post: by
|
1 post
views
Thread by kid_kei |
last post: by
|
8 posts
views
Thread by yinglcs |
last post: by
|
112 posts
views
Thread by istillshine |
last post: by
| | | | | | | | | | |