By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,318 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,318 IT Pros & Developers. It's quick & easy.

using global.asax

P: n/a
Hello,

On Microsoft Visual Studio .NET 2003,

I want to use some global elements,
that can be used in each one of my pages.
i.e I put a oleDBConnection on global.asax.vb

How can I use it (the oleDBConnection on global.asa.vb) at the other aspx
pages ?
Need sample code, please.

Thanks :)
Nov 19 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Why u need to use global.asax for something like this????

It was in ASP times...

If you need to specify a connection string that can be accessed via any
page, you should use web.config file.
Get it from web .config at application startup and add it application cache.
Access your connection string via application cache. But try to redesign
your architecture as at least two tier application.... Don't access database
from web pages....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

On Microsoft Visual Studio .NET 2003,

I want to use some global elements,
that can be used in each one of my pages.
i.e I put a oleDBConnection on global.asax.vb

How can I use it (the oleDBConnection on global.asa.vb) at the other aspx
pages ?
Need sample code, please.

Thanks :)

Nov 19 '05 #2

P: n/a
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database : web.config
is preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
Why u need to use global.asax for something like this????

It was in ASP times...

If you need to specify a connection string that can be accessed via any
page, you should use web.config file.
Get it from web .config at application startup and add it application
cache. Access your connection string via application cache. But try to
redesign your architecture as at least two tier application.... Don't
access database from web pages....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

On Microsoft Visual Studio .NET 2003,

I want to use some global elements,
that can be used in each one of my pages.
i.e I put a oleDBConnection on global.asax.vb

How can I use it (the oleDBConnection on global.asa.vb) at the other aspx
pages ?
Need sample code, please.

Thanks :)


Nov 19 '05 #3

P: n/a
.... besides - I think that web.config doesn't support *.mdb, but support sql
server - Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database : web.config
is preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
Why u need to use global.asax for something like this????

It was in ASP times...

If you need to specify a connection string that can be accessed via any
page, you should use web.config file.
Get it from web .config at application startup and add it application
cache. Access your connection string via application cache. But try to
redesign your architecture as at least two tier application.... Don't
access database from web pages....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

On Microsoft Visual Studio .NET 2003,

I want to use some global elements,
that can be used in each one of my pages.
i.e I put a oleDBConnection on global.asax.vb

How can I use it (the oleDBConnection on global.asa.vb) at the other
aspx pages ?
Need sample code, please.

Thanks :)



Nov 19 '05 #4

P: n/a
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but support sql server - Is
that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database : web.config is
preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
Why u need to use global.asax for something like this????

It was in ASP times...

If you need to specify a connection string that can be accessed via any page, you
should use web.config file.
Get it from web .config at application startup and add it application cache. Access
your connection string via application cache. But try to redesign your architecture as
at least two tier application.... Don't access database from web pages....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

On Microsoft Visual Studio .NET 2003,

I want to use some global elements,
that can be used in each one of my pages.
i.e I put a oleDBConnection on global.asax.vb

How can I use it (the oleDBConnection on global.asa.vb) at the other aspx pages ?
Need sample code, please.

Thanks :)



Nov 19 '05 #5

P: n/a
I agree with u this is a good example...
But i would like to add a few words on it...

At every time web.config file is changed application is restarted by asp.net
automatically my advice u to use global.asax at this point. Handle
applcation start event and add Application cache the values that u get from
web.config During the whole application use Application cache to access this
configuration parameters.

You can still use global.asax. But you should not !!!
--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but support
sql server - Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database :
web.config is preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
Why u need to use global.asax for something like this????

It was in ASP times...

If you need to specify a connection string that can be accessed via any
page, you should use web.config file.
Get it from web .config at application startup and add it application
cache. Access your connection string via application cache. But try to
redesign your architecture as at least two tier application.... Don't
access database from web pages....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> On Microsoft Visual Studio .NET 2003,
>
> I want to use some global elements,
> that can be used in each one of my pages.
> i.e I put a oleDBConnection on global.asax.vb
>
> How can I use it (the oleDBConnection on global.asa.vb) at the other
> aspx pages ?
> Need sample code, please.
>
> Thanks :)
>



Nov 19 '05 #6

P: n/a
Some clarifications :
--------------------------
1) For the code :
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)

2) I persume that global variables for db configuration, I best shall put it
on web.config.
Shall I put any of global variables on web.config (same method , <add
key = "mynewkey" value = "mynewvalue" />

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I agree with u this is a good example...
But i would like to add a few words on it...

At every time web.config file is changed application is restarted by
asp.net automatically my advice u to use global.asax at this point. Handle
applcation start event and add Application cache the values that u get
from web.config During the whole application use Application cache to
access this configuration parameters.

You can still use global.asax. But you should not !!!
--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but support
sql server - Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database :
web.config is preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
> Why u need to use global.asax for something like this????
>
> It was in ASP times...
>
> If you need to specify a connection string that can be accessed via
> any page, you should use web.config file.
> Get it from web .config at application startup and add it application
> cache. Access your connection string via application cache. But try to
> redesign your architecture as at least two tier application.... Don't
> access database from web pages....
>
> --
>
> Thanks,
> Yunus Emre ALPÍZEN
> BSc, MCAD.NET
>
> "John M" <nobody@nospam_please.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> Hello,
>>
>> On Microsoft Visual Studio .NET 2003,
>>
>> I want to use some global elements,
>> that can be used in each one of my pages.
>> i.e I put a oleDBConnection on global.asax.vb
>>
>> How can I use it (the oleDBConnection on global.asa.vb) at the other
>> aspx pages ?
>> Need sample code, please.
>>
>> Thanks :)
>>
>
>



Nov 19 '05 #7

P: n/a
.... Also I curious whether on every aspx page I need to open & close the
connection ?

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:ed**************@TK2MSFTNGP14.phx.gbl...
Some clarifications :
--------------------------
1) For the code :
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)

2) I persume that global variables for db configuration, I best shall put
it on web.config.
Shall I put any of global variables on web.config (same method , <add
key = "mynewkey" value = "mynewvalue" />

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I agree with u this is a good example...
But i would like to add a few words on it...

At every time web.config file is changed application is restarted by
asp.net automatically my advice u to use global.asax at this point.
Handle applcation start event and add Application cache the values that u
get from web.config During the whole application use Application cache to
access this configuration parameters.

You can still use global.asax. But you should not !!!
--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but
support sql server - Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
> So,
>
> I don't understand - why not using global.asax ?
> what you said is for database connection & accessing database :
> web.config is preferred.
> (If I need just simple temporary variables, I can use the
> global.asax).
>
> I need a sample code, please.
> (using connection, and accessing the database).
>
> Thanks :)
>
> "Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in
> message news:eD**************@TK2MSFTNGP12.phx.gbl...
>> Why u need to use global.asax for something like this????
>>
>> It was in ASP times...
>>
>> If you need to specify a connection string that can be accessed via
>> any page, you should use web.config file.
>> Get it from web .config at application startup and add it application
>> cache. Access your connection string via application cache. But try
>> to redesign your architecture as at least two tier application....
>> Don't access database from web pages....
>>
>> --
>>
>> Thanks,
>> Yunus Emre ALPÍZEN
>> BSc, MCAD.NET
>>
>> "John M" <nobody@nospam_please.com> wrote in message
>> news:%2****************@TK2MSFTNGP09.phx.gbl...
>>> Hello,
>>>
>>> On Microsoft Visual Studio .NET 2003,
>>>
>>> I want to use some global elements,
>>> that can be used in each one of my pages.
>>> i.e I put a oleDBConnection on global.asax.vb
>>>
>>> How can I use it (the oleDBConnection on global.asa.vb) at the other
>>> aspx pages ?
>>> Need sample code, please.
>>>
>>> Thanks :)
>>>
>>
>>
>
>



Nov 19 '05 #8

P: n/a
We've had several discussions on this, Yunus.
Maybe you missed them.

In essence, it doesn't matter whether you put the
connection data in web.config or in global.asax.

It's much easier to retrieve static application data from web.config,
though, since there's built-in methods for getting that data from it.

If you use global.asax you have to roll your own methods.

Regarding what you state :
every time web.config file is changed application is restarted by asp.net
automatically my advice u to use global.asax at this point.
The application is also restarted by asp.net when global.asax is changed,
so I don't understand what you're trying to say and why that would
stop you from recommending using web.config.

Regarding : Handle applcation start event and add Application cache the values that u get from
web.config
Why would you need to do that ?

ASP.NET *automatically* caches the contents of web.config for you
when the application starts, and everything in web.config is available
for retrieval from memory *without* having to cache it again.

Rethink this a bit, Yunus.


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

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...I agree with u this is a good example...
But i would like to add a few words on it...

At every time web.config file is changed application is restarted by asp.net
automatically my advice u to use global.asax at this point. Handle applcation start
event and add Application cache the values that u get from web.config During the whole
application use Application cache to access this configuration parameters.

You can still use global.asax. But you should not !!!
--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but support sql server -
Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
So,

I don't understand - why not using global.asax ?
what you said is for database connection & accessing database : web.config is
preferred.
(If I need just simple temporary variables, I can use the global.asax).

I need a sample code, please.
(using connection, and accessing the database).

Thanks :)

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
> Why u need to use global.asax for something like this????
>
> It was in ASP times...
>
> If you need to specify a connection string that can be accessed via any page, you
> should use web.config file.
> Get it from web .config at application startup and add it application cache. Access
> your connection string via application cache. But try to redesign your architecture
> as at least two tier application.... Don't access database from web pages....
>
> --
>
> Thanks,
> Yunus Emre ALPÍZEN
> BSc, MCAD.NET
>
> "John M" <nobody@nospam_please.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> Hello,
>>
>> On Microsoft Visual Studio .NET 2003,
>>
>> I want to use some global elements,
>> that can be used in each one of my pages.
>> i.e I put a oleDBConnection on global.asax.vb
>>
>> How can I use it (the oleDBConnection on global.asa.vb) at the other aspx pages ?
>> Need sample code, please.
>>
>> Thanks :)
>>
>
>



Nov 19 '05 #9

P: n/a
I agree with u.. Using web.config is recommended as you can see from my
first post. And my answer says
"You can still use global.asax. But you should not !!!" It is possible to
implement every thing what web.config brings out. But u should not !!! U
should use web.config instead of global.asax. I think, i was
misunderstood...

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uk****************@TK2MSFTNGP15.phx.gbl...
We've had several discussions on this, Yunus.
Maybe you missed them.

In essence, it doesn't matter whether you put the
connection data in web.config or in global.asax.

It's much easier to retrieve static application data from web.config,
though, since there's built-in methods for getting that data from it.

If you use global.asax you have to roll your own methods.

Regarding what you state :
every time web.config file is changed application is restarted by asp.net
automatically my advice u to use global.asax at this point.


The application is also restarted by asp.net when global.asax is changed,
so I don't understand what you're trying to say and why that would
stop you from recommending using web.config.

Regarding :
Handle applcation start event and add Application cache the values that u
get from web.config


Why would you need to do that ?

ASP.NET *automatically* caches the contents of web.config for you
when the application starts, and everything in web.config is available
for retrieval from memory *without* having to cache it again.

Rethink this a bit, Yunus.


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

"Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I agree with u this is a good example...
But i would like to add a few words on it...

At every time web.config file is changed application is restarted by
asp.net automatically my advice u to use global.asax at this point.
Handle applcation start event and add Application cache the values that u
get from web.config During the whole application use Application cache to
access this configuration parameters.

You can still use global.asax. But you should not !!!
--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
Wrong.

See a complete example for storing a connection string
in web.config, and the code necessary to retrieve that
connection string, to connect to an Access database at :

http://www.webforumz.com/viewtopic.p...a9b9a6f4a4dc94

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

"John M" <nobody@nospam_please.com> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
... besides - I think that web.config doesn't support *.mdb, but
support sql server - Is that true ?
(what I use is *.mdb)

Thanks :)

"John M" <nobody@nospam_please.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
> So,
>
> I don't understand - why not using global.asax ?
> what you said is for database connection & accessing database :
> web.config is preferred.
> (If I need just simple temporary variables, I can use the
> global.asax).
>
> I need a sample code, please.
> (using connection, and accessing the database).
>
> Thanks :)
>
> "Yunus Emre ALPÍZEN [MCAD.NET]" <ye***@msakademik.net> wrote in
> message news:eD**************@TK2MSFTNGP12.phx.gbl...
>> Why u need to use global.asax for something like this????
>>
>> It was in ASP times...
>>
>> If you need to specify a connection string that can be accessed via
>> any page, you should use web.config file.
>> Get it from web .config at application startup and add it application
>> cache. Access your connection string via application cache. But try
>> to redesign your architecture as at least two tier application....
>> Don't access database from web pages....
>>
>> --
>>
>> Thanks,
>> Yunus Emre ALPÍZEN
>> BSc, MCAD.NET
>>
>> "John M" <nobody@nospam_please.com> wrote in message
>> news:%2****************@TK2MSFTNGP09.phx.gbl...
>>> Hello,
>>>
>>> On Microsoft Visual Studio .NET 2003,
>>>
>>> I want to use some global elements,
>>> that can be used in each one of my pages.
>>> i.e I put a oleDBConnection on global.asax.vb
>>>
>>> How can I use it (the oleDBConnection on global.asa.vb) at the other
>>> aspx pages ?
>>> Need sample code, please.
>>>
>>> Thanks :)
>>>
>>
>>
>
>



Nov 19 '05 #10

P: n/a
re:
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)
Either inline in your aspx page, or in your codebehind if you're using that.

Here's an inline example :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim DS As DataSet
Dim MyConnection As String
Dim MyCommand As SqlDataAdapter

MyConnection = ConfigurationSettings.AppSettings("connNorthwind")

MyCommand = New SqlDataAdapter("select * from orders where orderid = 10270", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater.DataSource = DS
Repeater.DataBind()

End Sub

This assumes that your web.config entry looks like this :

<configuration>

<appSettings>
<add key="connNorthwind" value="server=(local);trusted_connection=true;data base=northwind"/>
</appSettings>

Make sure you replace *your* SQL server's name in this string.

re: 2) I presume that global variables for db configuration,
I best shall put it on web.config.
Yes.
Shall I put any of global variables on web.config (same method ,
<add key = "mynewkey" value = "mynewvalue" />
Exactly.

Now, for a news update :

All this changes in ASP.NET 2.0. News at 2.

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

"John M" <nobody@nospam_please.com> wrote in message news:ed**************@TK2MSFTNGP14.phx.gbl... Some clarifications :
--------------------------
1) For the code :
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)

2) I persume that global variables for db configuration, I best shall put it
on web.config.
Shall I put any of global variables on web.config (same method , <add
key = "mynewkey" value = "mynewvalue" />

Thanks :)


Nov 19 '05 #11

P: n/a
That's O.K.
But, as I have mention earlier :

.... on every aspx page I need to open & close the
connection, if I do as your advise.

So I have solved it as follows :
------------------------------------------
If I put on session_start (global.asax.vb) the code :
Session("conMain") = me.conMain
(me.conMain is oleDBConnection).

I can reference on every of my aspx pages on their page_load event as following :
OleDBCommand1.Connection = Session("conMain").
(oleDBCommand1 is oleDBCommand).
----------------------------------------------------------------------
.... which is much easier to maintenance

One thing is that on global.asax.vb the event : InitializeComponent is called twice, but only when first running the application
(If I run the application again : InitializeComponent isn't called).
And I don't understand why.

Another thing is that I was advised (former to this forum) not using global.asax.vb for using Session("conMain") -
Another thing I don't understand why.

Is my solution has any problem using it ?

Thanks :)

"Juan T. Llibre" <no***********@nowhere.com> wrote in message news:uP**************@TK2MSFTNGP14.phx.gbl...
re:
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)
Either inline in your aspx page, or in your codebehind if you're using that.

Here's an inline example :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim DS As DataSet
Dim MyConnection As String
Dim MyCommand As SqlDataAdapter

MyConnection = ConfigurationSettings.AppSettings("connNorthwind")

MyCommand = New SqlDataAdapter("select * from orders where orderid = 10270", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater.DataSource = DS
Repeater.DataBind()

End Sub

This assumes that your web.config entry looks like this :

<configuration>

<appSettings>
<add key="connNorthwind" value="server=(local);trusted_connection=true;data base=northwind"/>
</appSettings>

Make sure you replace *your* SQL server's name in this string.

re: 2) I presume that global variables for db configuration,
I best shall put it on web.config.
Yes.
Shall I put any of global variables on web.config (same method ,
<add key = "mynewkey" value = "mynewvalue" />
Exactly.

Now, for a news update :

All this changes in ASP.NET 2.0. News at 2.

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

"John M" <nobody@nospam_please.com> wrote in message news:ed**************@TK2MSFTNGP14.phx.gbl... Some clarifications :
--------------------------
1) For the code :
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)

2) I persume that global variables for db configuration, I best shall put it
on web.config.
Shall I put any of global variables on web.config (same method , <add
key = "mynewkey" value = "mynewvalue" />

Thanks :)


Nov 19 '05 #12

P: n/a
I think only one person would use your application at the same time... Or one call for one session. What happens a user opens two different pages at the same time...

It has too many problem... My advice u take a look at duwamish sample....

--

Thanks,
Yunus Emre ALPÍZEN
BSc, MCAD.NET

"John M" <nobody@nospam_please.com> wrote in message news:Os**************@TK2MSFTNGP15.phx.gbl...
That's O.K.
But, as I have mention earlier :

... on every aspx page I need to open & close the
connection, if I do as your advise.

So I have solved it as follows :
------------------------------------------
If I put on session_start (global.asax.vb) the code :
Session("conMain") = me.conMain
(me.conMain is oleDBConnection).

I can reference on every of my aspx pages on their page_load event as following :
OleDBCommand1.Connection = Session("conMain").
(oleDBCommand1 is oleDBCommand).
----------------------------------------------------------------------
... which is much easier to maintenance

One thing is that on global.asax.vb the event : InitializeComponent is called twice, but only when first running the application
(If I run the application again : InitializeComponent isn't called).
And I don't understand why.

Another thing is that I was advised (former to this forum) not using global.asax.vb for using Session("conMain") -
Another thing I don't understand why.

Is my solution has any problem using it ?

Thanks :)

"Juan T. Llibre" <no***********@nowhere.com> wrote in message news:uP**************@TK2MSFTNGP14.phx.gbl...
re:
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)
Either inline in your aspx page, or in your codebehind if you're using that.

Here's an inline example :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim DS As DataSet
Dim MyConnection As String
Dim MyCommand As SqlDataAdapter

MyConnection = ConfigurationSettings.AppSettings("connNorthwind")

MyCommand = New SqlDataAdapter("select * from orders where orderid = 10270", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Orders")

Repeater.DataSource = DS
Repeater.DataBind()

End Sub

This assumes that your web.config entry looks like this :

<configuration>

<appSettings>
<add key="connNorthwind" value="server=(local);trusted_connection=true;data base=northwind"/>
</appSettings>

Make sure you replace *your* SQL server's name in this string.

re: 2) I presume that global variables for db configuration,
I best shall put it on web.config.
Yes.
Shall I put any of global variables on web.config (same method ,
<add key = "mynewkey" value = "mynewvalue" />
Exactly.

Now, for a news update :

All this changes in ASP.NET 2.0. News at 2.

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

"John M" <nobody@nospam_please.com> wrote in message news:ed**************@TK2MSFTNGP14.phx.gbl... Some clarifications :
--------------------------
1) For the code :
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
- Where shall I put it (not web.config ?)

2) I persume that global variables for db configuration, I best shall put it
on web.config.
Shall I put any of global variables on web.config (same method , <add
key = "mynewkey" value = "mynewvalue" />

Thanks :)


Nov 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.