|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
using global.asaxHello,
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 :) 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.... -- Show quoteHide quoteThanks, Yunus Emre ALPÖZEN BSc, MCAD.NET "John M" <nobody@nospam_please.com> wrote in message news:%23siPvMGWFHA.3620@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 :) > 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 :) Show quoteHide quote "Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message news:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >> > > .... besides - I think that web.config doesn't support *.mdb, but support sql
server - Is that true ? (what I use is *.mdb) Thanks :) Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>> >> >> > > 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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 Juan T. Llibre ASP.NET MVP http://asp.net.do/foros/ Foros de ASP.NET en Español Ven, y hablemos de ASP.NET... ====================== Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>> >>> >>> >> >> > > 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 !!! -- Show quoteHide quoteThanks, Yunus Emre ALPÖZEN BSc, MCAD.NET "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message news:usFZdkIWFHA.3280@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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 > > > > 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:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>>> >>>> >>>> >>> >>> >> >> > > Some clarifications :
-------------------------- 1) For the code : strConnection = ConfigurationSettings.AppSettings("ConnectionString") 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 :) Show quoteHide quote "Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message news:%23Y6PVOKWFHA.2472@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" <nomailrepl***@nowhere.com> wrote in message > news:usFZdkIWFHA.3280@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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 >> >> >> >> 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:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > .... Also I curious whether on every aspx page I need to open & close the
connection ? Thanks :) Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:edxFywLWFHA.4076@TK2MSFTNGP14.phx.gbl... > Some clarifications : > -------------------------- > 1) For the code : > strConnection = ConfigurationSettings.AppSettings("ConnectionString") > 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:%23Y6PVOKWFHA.2472@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" <nomailrepl***@nowhere.com> wrote in message >> news:usFZdkIWFHA.3280@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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 >>> >>> >>> >>> 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:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > re:
> strConnection = ConfigurationSettings.AppSettings("ConnectionString") Either inline in your aspx page, or in your codebehind if you're using that.> sqlConn = New SqlConnection(strConnection) > - Where shall I put it (not web.config ?) 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;database=northwind"/> </appSettings> Make sure you replace *your* SQL server's name in this string. re: > 2) I presume that global variables for db configuration, Yes.> I best shall put it on web.config. > Shall I put any of global variables on web.config (same method , Exactly.> <add key = "mynewkey" value = "mynewvalue" /> 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... ====================== Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:edxFywLWFHA.4076@TK2MSFTNGP14.phx.gbl... > Some clarifications : > -------------------------- > 1) For the code : > strConnection = ConfigurationSettings.AppSettings("ConnectionString") > 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 :) 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" <nomailrepl***@nowhere.com> wrote in message news:uP3UBTUWFHA.1240@TK2MSFTNGP14.phx.gbl... Either inline in your aspx page, or in your codebehind if you're using that.re: > strConnection = ConfigurationSettings.AppSettings("ConnectionString") > sqlConn = New SqlConnection(strConnection) > - Where shall I put it (not web.config ?) 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;database=northwind"/> </appSettings> Make sure you replace *your* SQL server's name in this string. re: > 2) I presume that global variables for db configuration, Yes.> I best shall put it on web.config. > Shall I put any of global variables on web.config (same method , Exactly.> <add key = "mynewkey" value = "mynewvalue" /> 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... ====================== Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:edxFywLWFHA.4076@TK2MSFTNGP14.phx.gbl... > Some clarifications : > -------------------------- > 1) For the code : > strConnection = ConfigurationSettings.AppSettings("ConnectionString") > 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 :) 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:Os7m0dYWFHA.3760@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" <nomailrepl***@nowhere.com> wrote in message news:uP3UBTUWFHA.1240@TK2MSFTNGP14.phx.gbl... re: > strConnection = ConfigurationSettings.AppSettings("ConnectionString") Either inline in your aspx page, or in your codebehind if you're using that.> sqlConn = New SqlConnection(strConnection) > - Where shall I put it (not web.config ?) 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;database=northwind"/> </appSettings> Make sure you replace *your* SQL server's name in this string. re: > 2) I presume that global variables for db configuration, Yes.> I best shall put it on web.config. > Shall I put any of global variables on web.config (same method , Exactly.> <add key = "mynewkey" value = "mynewvalue" /> 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... ====================== Show quoteHide quote "John M" <nobody@nospam_please.com> wrote in message news:edxFywLWFHA.4076@TK2MSFTNGP14.phx.gbl... > Some clarifications : > -------------------------- > 1) For the code : > strConnection = ConfigurationSettings.AppSettings("ConnectionString") > 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 :) 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 The application is also restarted by asp.net when global.asax is changed,> automatically my advice u to use global.asax at this point. 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 Why would you need to do that ?> web.config 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... ====================== Show quoteHide quote "Yunus Emre ALPÖZEN [MCAD.NET]" <ye***@msakademik.net> wrote in message news:%23Y6PVOKWFHA.2472@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" <nomailrepl***@nowhere.com> wrote in message > news:usFZdkIWFHA.3280@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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 >> >> >> >> 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:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > 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... -- Show quoteHide quoteThanks, Yunus Emre ALPÖZEN BSc, MCAD.NET "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message news:uk6Ia%23TWFHA.2128@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:%23Y6PVOKWFHA.2472@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" <nomailrepl***@nowhere.com> wrote in message >> news:usFZdkIWFHA.3280@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.php?p=19829&sid=152babdb1aaf994cdea9b9a6f4a4dc94 >>> >>> >>> >>> 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:OU04F$GWFHA.2960@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:%23I6NS8GWFHA.616@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:eDakqgGWFHA.3176@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:%23siPvMGWFHA.3620@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 :) >>>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Dynamically Adding Controls
Updating a DB via SQL is giving me a headache Reading IP.... Composite Controls, eventhandlers and knowing which control caused postback thread.start() does not actually execute the assigned method Redirecting to a page with a querystring and an anchor reference Uploading graphics. DropDownList Control Problem with UrlMappings link text box to datasource |
|||||||||||||||||||||||