|
Thanks for the reply.
My question is really concerning whether it is possible for the master page to access the connection already opened by the content page. So far I haven’t found a way to do this.
|
|
|
|
|
Yes, it is possible, just as it is possible to drop bowling balls on your feet to get out of ballroom dancing with your girl friend. Hardly the best way of doing it. Just as Colin said, aquire-execute-release.
only two letters away from being an asset
|
|
|
|
|
It's possible to use the same connection, if you have a method in the master page where you do the database work, which you call from the contents page. However, as you open the connection before the master page is even loaded, you would have to keep the connection open from one event to another, which would make it much harder to ensure that the connection is always closed correctly.
It's hard to tell if opening another connection will be slower or not, but it's safe to say that the difference is not that big. As long as you use an identical connection string the connections are pooled, which means that they are never really closed between the times they are used. So if you keep the connection alive or let the pool do it shouldn't matter much when it comes to speed. As it's much safer to leave it to the pool, you should do that.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
I figured the easiest way to do it would be to open the connection in the content page PreInit and close it in the content page Unload. This way the connection is open when the master page Load event fires, which is when it should be used. But, I can’t find a way to access the open connection.
I’m not sure how to access a master page function from the contents page, bearing in mind that the master page is defined at runtime.
|
|
|
|
|
BigPaul wrote: I’m not sure how to access a master page function from the contents page, bearing in mind that the master page is defined at runtime
You can access the master page from the content page by using the content page's Master property. However, the best solution is to aquire-execute-release in the master and aquire-execute-release in the content page. Actually, a better solution would be to move all the data access out of the presentation layer altogether.
Daniel Fisher (I think) at the DDD4 conference I was at earlier this month gave some pretty sage advice: If you are using anything in the System.Data namespace in your code behind classes (e.g. The code behind for Master pages or Content pages) then there is something wrong with your design.
|
|
|
|
|
I was under the impression (clearly the wrong impression) that opening and closing a connection twice would be slower than doing it once, and that opening a connection in one event and closing it in another immediately-following event would not be a problem – i.e. this it was essentially an ‘acquire-execute-release’ approach.
However, having since read up on connection pooling, it is obviously not necessary to try and keep the connection open.
Colin Angus Mackay wrote: Daniel Fisher (I think) at the DDD4 conference I was at earlier this month gave some pretty sage advice: If you are using anything in the System.Data namespace in your code behind classes (e.g. The code behind for Master pages or Content pages) then there is something wrong with your design.
Is there a disadvantage to accessing a database from the code-behind class? The data access for my master pages is handled in a separate class, but the content page accesses the database directly. I’m interested to know if there is a more efficient approach.
|
|
|
|
|
BigPaul wrote: Is there a disadvantage to accessing a database from the code-behind class?
Yes. It reduces maintainability of the appliction.
BigPaul wrote: I’m interested to know if there is a more efficient approach.
Efficiency (or performance, what ever you want to call it) is usually not one of my top priorities when writing software. Maintainability and Readability come first unless performance considerations are an explicit part of the specification.
I will always go for readability or maintainability even if it costs me a few extra clock cycles because nothing is worse than having to debug code written using the "Giant Ball of Mud" pattern.
If you separate out the database access into its own class (or classes) you get improved readability because your code behind is not cluttered with calls to open connections, set up queries, execute queries and close everything down again - You let the DAL (Data Abstraction Layer - the class[es] that you write) handle that.
You get improved maintainability because all your data access code in in one place (the DAL). This means that if you have to make any substantial changes to the database you don't have to go looking over an entire code base.
You can even get improved efficiency with a DAL if you work it right. For example, you would normally get a connection string out of the config file. The DAL can do that once then cache it. The DAL is always using the cached connection string so that connection pooling works better (there is no accidental use of a slightly different connection string to get to the same thing - which creates a new pool).
|
|
|
|
|
BigPaul wrote: and that opening a connection in one event and closing it in another immediately-following event would not be a problem
It is a problem if the second event never is executed. If you encounter an error somewhere in your code between opening and closing the connection, the event that closes the connection will never be executed and the connection will be left open.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hi
I am working on asp.net and i want to write a program in asp.net i.e to get the date and time of different countries on selecting the countries name.So can any one help me out?
Thanks...
Deepti
|
|
|
|
|
deeptis wrote: I am working on asp.net and i want to write a program in asp.net i.e to get the date and time of different countries on selecting the countries name.So can any one help me out?
I'm sure there are many people. What part are you stuck with?
|
|
|
|
|
Hi all , I'm studying a case study from Microsoft about CommonWealth Bank using SOA.
Any way ..during studying I'm facing some problems in imagination for implementing some features..
1)how to add specific pieces of information or data to the response and request in order to be passed from one module for example to another or from the server to client and vice versa?
2)how can I get access to the that response of the WebSerice ?-can just call method from proxy class-
3)what is Soap Handlers ? Have not heared about it before!!!
4)Attributes have the ability to generate code for method at run time or maybe link this method to the implementation at run time ?
5)Any idea about what is LDAP and AZMAN and how to use them in authorization with active directory ?
that is what have been saied and what i'm trying to understand .. I really appreciate your help or linking me to helpful resources
My Regards
Davids Maguire
|
|
|
|
|
how can i put the datalist up in the top of a table because its coming in the middle of the table row. all i have is just 1 record into a datalist and it is coming with alot of space inside the table and the datalist in the middle of that space. why is this?
Thanks
Adrian De Battista: .Net Programmer, Java Programmer and Web Designer.
|
|
|
|
|
I guess you only need to change the valign property in the the table row to top and it will be displayed properly.
Mohamed El Gohary
|
|
|
|
|
Hi all
I have written a code for uploading a photo.
but my code does this :
insert the picture into database.
but my aim is to upload a picture in a web page and then the picture will be shown in the webpage ( explorer)
Can you help me please?
What should I do?
the picture will be sent in database but how to show it from database to webpage??
I use Visual studio2003 and SQlserver2000 and my language is C#
Thanks alot.
-- modified at 8:53 Sunday 17th December, 2006
|
|
|
|
|
How about doing a query to the DB get the Image then bind an Image control to the DB
|
|
|
|
|
hi
I used "insert to " to insert the picture into database.the picture is now in the database.but how can I view it in a webpage?
I cant understand what u meant : "bind an Image control to the DB"
What do u mean?
can u tell me the code plz? the code for showing picture?
|
|
|
|
|
Well why don't you go ahead and display the picture (the gpeg or whatever format file) you have in the browser before storing it to the database. You can do that by setting the imageUrl property of an Image control to the path where you are putting the image. For instance localhost/MyApp/Pictures/myPicture.gif. Make sure you create this folder (Picture) with the image and dump it in your project folder and then also add it in your application.
Good luck
|
|
|
|
|
I use crystal report to export pdf file in my web application.
My crystal report file name is testreport. I user these commands to export:
testreport report = new testreport();
report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "aaa.pdf");
But when I run it I have error:
"Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Error in File C:\DOCUME~1\EHSAN-~1\ASPNET\LOCALS~1\Temp\temp_5a2db3c1-f7ea-455d-a5c1-c37a91b5f8a9.rpt: Access to report file denied. Another program may be using it."
I never use this file:"C:\DOCUME~1\EHSAN-~1\ASPNET\LOCALS~1\Temp\temp_5a2db3c1-f7ea-455d-a5c1-c37a91b5f8a9.rpt"
But the error is that file is in use. Please help me.
I develop with visual studio 2003, my language C#.net.
Thanks
Rastgar
|
|
|
|
|
I have never used Crystal reports , so not really familiar with this error,
but what I would think that CR is probably creating a temporary file that it will use to create the report, and to do this the ASP net worker process may need access to that directory so I would check that the worker process had read/write permission to your temporary folder
It's just a guess,
|
|
|
|
|
How can I set full access for this folder?
Please explain it step by step if it is possible .
Thanks
Rastgar
|
|
|
|
|
Copy this code in button click for transfering crystal report data to pdf
format:The pdf will be stored inside the project location that for example
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\WebSite2
Dim rptExcel As New ReportDocument
Dim strExportFile As String = Server.MapPath(".") & "/Reports.pdf"
rptExcel.Load(Server.MapPath("CrystalReport.rpt"))
rptExcel.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
rptExcel.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
Dim objOptions As DiskFileDestinationOptions = New DiskFileDestinationOptions
objOptions.DiskFileName = strExportFile
rptExcel.ExportOptions.DestinationOptions = objOptions
rptExcel.Export()
objOptions = Nothing
rptExcel = Nothing
|
|
|
|
|
using toggled value with in the column like stop and start when clicking start stop should be hide and again when clicking stop then start should be hide so i have tried this using div but could not get result so anybody has suffering from such kinds of troubled and have solution then give me the hints i will be appreciates for u.
hikbnet
|
|
|
|
|
In your datasource, there should be a column which denotes start or stop. let start is denoted by 1 and stop by 0.
What you have to do is just write a function which will toggle the values. Or if you are using image, it will show the image of start when it is 0, and the image of stop when it is 1.
the code will be something like
<br />
<%# GetToggledValue(DataBinder.Eval(Container, "DataItem.Status")) %><br />
here status is the name of the column for start and stop, and GetToggledValue() is the function.
Pradipta Basu
|
|
|
|
|
Thank's for your kinds hints but it may works like data list but it is difficult to implement in case of data grid if any further suggestion plz reply me okey thank's a lot .
hikbnet
|
|
|
|
|
It works with DataGrid. You have to use TemplateColumn
Pradipta Basu
|
|
|
|