473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

using global.asax

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
12 3788
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
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
.... 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
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
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
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
.... 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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Luther Hert | last post by:
While trying to work through textbook lessons for Vb.net Step by Step,Version 2003, Chapter 22, the first step is to create a new Web application Project,using the ASP.Net Application icon in the...
22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
1
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
8
by: Victor | last post by:
Can I get the events in GLOBAL.ASAX to fire if a classic ASP page is being accessed by the user?
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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

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