Global.asax文件

编程入门 行业动态 更新时间:2024-10-27 10:26:51
本文介绍了Global.asax文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对global.asax.cs文件有疑问。我是从数据库中读取信息以填充DataGrid。我在某个地方读到了,数据库的开放应该在global.asax.cs文件中出现,每次请求都会发生没有'再次打开数据库。 这是怎么做到的?全局文件 似乎无法访问位于 index.aspx文件中的DataGrid web控件。只有index.aspx.cs文件可以访问 这个控件。 另外,我尝试将连接对象放在 $ b $中b global.asax.cs文件,但无法在 index.aspx.cs文件中引用它。 填充DataGrid的最佳做法是什么来自 a数据库表?我想我可以打开 数据库,填充DataGrid并关闭global.asax.cs文件'的Application_Start()中的连接 > 事件处理程序。然后在index.aspx.cs文件中,只需 重新绑定控件。 有人请举例说明这是怎么回事/> 完成了吗? 谢谢, Prince

解决方案

你读错了。 不要在你的网站上使用相同的连接。这将非常糟糕 并且会严重限制您的可扩展性。 ADO.NET内置了连接池。 因此你应该打开一个您需要在 页面之前的数据库连接,并尽快关闭数据库连接。连接 池化使这非常有效。 - 我希望这会有所帮助, Steve C. Orr,MCSD,MVP Steve.Orr 聘请顶尖的开发人员参加 http:// www。 able-consulting " Prince" < PR ****** @ cox>在消息中写道 news:03 **************************** @ phx.gbl ... 我对global.asax.cs文件有疑问。我是从数据库中读取信息以填充DataGrid。我在某处读到了数据库的打开应该发生在global.asax.cs文件中,这样每个请求都不会再次打开数据库。 无法访问位于 index.aspx文件中的DataGrid web控件。只有index.aspx.cs文件可以访问这个控件。 另外,我尝试将连接对象放在 global.asax.cs文件中,但是无法引用它在 index.aspx.cs文件中。 从数据库表填充DataGrid的最佳实践是什么?我想我可以在global.asax.cs文件的Application_Start()事件处理程序中打开数据库,填充DataGrid并关闭连接。然后在index.aspx.cs文件中,重新绑定控件。 是否有人请举例说明这是如何完成的? 谢谢,王子

我是这样做的... 在Global.asax中,我拖动我需要的DbConnections。我添加DbCommands为 需要。我根据需要添加了DbDataAdapters。 所以,对于每个数据库,我都有一个连接 对于每个连接,我有4个命令 对于每个连接,我有一个适配器 这就是Global.asax所拥有的,我需要在任何页面上使用的对象实例网站 在页面上我想使用这些对象我声明一个变量就像这样 -------- ------------- 作为New Global的私人意见 ---------------- ----- 现在我可以使用变量wrMain来定义像这样的对象 -------- ----------------- Dim ds作为新数据集 尝试 Me.wrMain .DbConn.Open() Me.wrMain.DbSelect.CommandText =" SQL TEXT" Me.wrMain.DbAdapter.Fill(ds," tablename") Me.DataGrid.DataSource = ds Me.DataGrid.DataMember = ds.Tables(0).TableName Me.DataGrid.DataBind () Catch ex as Exception Me.lblError.Text =" Error ..." &安培; ex.Message 最后 Me.wrMain.DbConn.Close() 结束尝试 --- --------------------------- " Prince" < PR ****** @ cox>在消息中写道 news:03 **************************** @ phx.gbl ... 我对global.asax.cs文件有疑问。我是从数据库中读取信息以填充DataGrid。我在某处读到了数据库的打开应该发生在global.asax.cs文件中,这样每个请求都不会再次打开数据库。 无法访问位于 index.aspx文件中的DataGrid web控件。只有index.aspx.cs文件可以访问这个控件。 另外,我尝试将连接对象放在 global.asax.cs文件中,但是无法引用它在 index.aspx.cs文件中。 从数据库表填充DataGrid的最佳实践是什么?我想我可以在global.asax.cs文件的Application_Start()事件处理程序中打开数据库,填充DataGrid并关闭连接。然后在index.aspx.cs文件中,重新绑定控件。 是否有人请举例说明这是如何完成的? 谢谢,王子

你读过史蒂夫的回复吗?他说你做的很糟糕。你应该停止这样做,而不是试图解释你为什么这样做。 你仍然有全局句柄控制连接对象泄漏资源。 - 问候, Alvin Bruney 得到花絮?在此处获取 wwwworkip/tidbits " news.airmail" < SA ******* @ airmail>在消息中写道 news:bq ******** @ library2.airnews ...

这是我怎么做的...... 在Global.asax中,我拖动了我需要的DbConnections。我需要添加DbCommands。我根据需要添加DbDataAdapters。 因此,对于每个数据库,我都有一个连接对于每个连接,我有4个命令对于每个连接,我有一个适配器 <这就是Global.asax所拥有的一切,我需要在网站的任何页面上使用的对象实例 在页面上我想要使用这些对象我宣布一个像这样的变量 --------------------- 私人意志作为新的全球 - ------------------- 现在我可以使用变量wrMain来定义像这样的对象 - ----------------------- Dim ds as New DataSet 尝试 Me.wrMain.DbConn.Open() Me.wrMain.DbSelect.CommandText =" SQL TEXT" Me.wrMain.DbAdapter.Fill(ds," tablename") Me.DataGrid.DataSource = ds Me.DataGrid.DataMember = ds.Tables(0).TableName Me.DataGrid.DataBind() Catch ex as Exception Me.lblError.Text ="错误... &现状吨; &安培; ex.Message 最后 Me.wrMain.DbConn.Close()结束尝试 ------------------- ----------- 王子 < PR ****** @ cox>在消息中写道新闻:03 **************************** @ phx.gbl ...

我对global.asax.cs文件有疑问。我是从数据库中读取信息以填充DataGrid。我在某处读到了数据库的打开应该发生在global.asax.cs文件中,这样每个请求都不会再次打开数据库。 无法访问位于 index.aspx文件中的DataGrid web控件。只有index.aspx.cs文件可以访问这个控件。 另外,我尝试将连接对象放在 global.asax.cs文件中,但是无法引用它在 index.aspx.cs文件中。 从数据库表填充DataGrid的最佳实践是什么?我想我可以在global.asax.cs文件的Application_Start()事件处理程序中打开数据库,填充DataGrid并关闭连接。然后在index.aspx.cs文件中,重新绑定控件。 是否有人请举例说明这是如何完成的? 谢谢,王子

I have a question about the global.asax.cs file. I''m reading info from a database to populate a DataGrid. I read somewhere that the opening of the database should occur in the global.asax.cs file that way every request doesn''t open the database again. How is this done? It doesn''t seem that the global file can access the DataGrid webcontrol, located on the index.aspx, file. Only the index.aspx.cs file can access this control. Also, I tried putting the connection object inside the global.asax.cs file but could not reference it in the index.aspx.cs file. What is the best practice for populating a DataGrid from a database table? I would think I could open the database, populate the DataGrid and close the connection all within the global.asax.cs file''s Application_Start() event handler. Then within the index.aspx.cs file, just re-bind the control. Does someone please give me an example of how this is done? thanks, Prince

解决方案

You read wrong. Do not use the same connection throughout your site. This would be very bad and would limit your scalability severely. ADO.NET has built in connection pooling. Therefore you should open a database connection just before you need it on a page, and close the database connection as soon as possible. The connection pooling makes this very efficient. -- I hope this helps, Steve C. Orr, MCSD, MVP Steve.Orr Hire top-notch developers at www.able-consulting "Prince" <pr******@cox> wrote in message news:03****************************@phx.gbl...

I have a question about the global.asax.cs file. I''m reading info from a database to populate a DataGrid. I read somewhere that the opening of the database should occur in the global.asax.cs file that way every request doesn''t open the database again. How is this done? It doesn''t seem that the global file can access the DataGrid webcontrol, located on the index.aspx, file. Only the index.aspx.cs file can access this control. Also, I tried putting the connection object inside the global.asax.cs file but could not reference it in the index.aspx.cs file. What is the best practice for populating a DataGrid from a database table? I would think I could open the database, populate the DataGrid and close the connection all within the global.asax.cs file''s Application_Start() event handler. Then within the index.aspx.cs file, just re-bind the control. Does someone please give me an example of how this is done? thanks, Prince

Here is how I do it... In Global.asax I drag the DbConnections that I need. I add DbCommands as needed. I add DbDataAdapters as needed. So, for each database I have a connection For each connection I have 4 commands For each connection I have an Adapter That is all that the Global.asax holds, an instance of the objects that I need to use on any page of the website On the page I want to use these objects I declare a Variable like so --------------------- Private wrMain as New Global --------------------- Now I can use the variable wrMain to define the objects like so ------------------------- Dim ds as New DataSet Try Me.wrMain.DbConn.Open() Me.wrMain.DbSelect.CommandText = "SQL TEXT" Me.wrMain.DbAdapter.Fill(ds, "tablename") Me.DataGrid.DataSource = ds Me.DataGrid.DataMember = ds.Tables(0).TableName Me.DataGrid.DataBind() Catch ex as Exception Me.lblError.Text = "Error... " & ex.Message Finally Me.wrMain.DbConn.Close() End Try ------------------------------ "Prince" <pr******@cox> wrote in message news:03****************************@phx.gbl...

I have a question about the global.asax.cs file. I''m reading info from a database to populate a DataGrid. I read somewhere that the opening of the database should occur in the global.asax.cs file that way every request doesn''t open the database again. How is this done? It doesn''t seem that the global file can access the DataGrid webcontrol, located on the index.aspx, file. Only the index.aspx.cs file can access this control. Also, I tried putting the connection object inside the global.asax.cs file but could not reference it in the index.aspx.cs file. What is the best practice for populating a DataGrid from a database table? I would think I could open the database, populate the DataGrid and close the connection all within the global.asax.cs file''s Application_Start() event handler. Then within the index.aspx.cs file, just re-bind the control. Does someone please give me an example of how this is done? thanks, Prince

Did you read Steve''s response. He said that what you are doing is bad. You should stop doing it and not try to explain why you are doing it this way. You still have global handles holding connection objects leaking resources. -- Regards, Alvin Bruney Got Tidbits? Get it here wwwworkip/tidbits "news.airmail" <sa*******@airmail> wrote in message news:bq********@library2.airnews...

Here is how I do it... In Global.asax I drag the DbConnections that I need. I add DbCommands as needed. I add DbDataAdapters as needed. So, for each database I have a connection For each connection I have 4 commands For each connection I have an Adapter That is all that the Global.asax holds, an instance of the objects that I need to use on any page of the website On the page I want to use these objects I declare a Variable like so --------------------- Private wrMain as New Global --------------------- Now I can use the variable wrMain to define the objects like so ------------------------- Dim ds as New DataSet Try Me.wrMain.DbConn.Open() Me.wrMain.DbSelect.CommandText = "SQL TEXT" Me.wrMain.DbAdapter.Fill(ds, "tablename") Me.DataGrid.DataSource = ds Me.DataGrid.DataMember = ds.Tables(0).TableName Me.DataGrid.DataBind() Catch ex as Exception Me.lblError.Text = "Error... " & ex.Message Finally Me.wrMain.DbConn.Close() End Try ------------------------------ "Prince" <pr******@cox> wrote in message news:03****************************@phx.gbl...

I have a question about the global.asax.cs file. I''m reading info from a database to populate a DataGrid. I read somewhere that the opening of the database should occur in the global.asax.cs file that way every request doesn''t open the database again. How is this done? It doesn''t seem that the global file can access the DataGrid webcontrol, located on the index.aspx, file. Only the index.aspx.cs file can access this control. Also, I tried putting the connection object inside the global.asax.cs file but could not reference it in the index.aspx.cs file. What is the best practice for populating a DataGrid from a database table? I would think I could open the database, populate the DataGrid and close the connection all within the global.asax.cs file''s Application_Start() event handler. Then within the index.aspx.cs file, just re-bind the control. Does someone please give me an example of how this is done? thanks, Prince

更多推荐

Global.asax文件

本文发布于:2023-11-04 10:07:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557639.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Global   asax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!