Closing DB Connection-Best Practice

Currently I am opening and closing my connection to the database on each event that warrants a database connection. Is this the way I should handle it, or should I open the connection at the beginning and close it at the end, leaving it open in between?
I have a certain panel that has numerous, separate inputs to a database that are isolated from each other, and if I happen to use all of these inputs, I open and close the connection 3 or 4 times.
Thanks

Hi,
As far as an application is concerned we usually wont advice opening and closing connection as and when necessary. But if the connection is open for a long time there are some possible problems. One is that if the server goes down the user wont be aware of that till he executes the next query and also the error wont will be a valid one.Next is the amount of time ther server holds the connection and this has its significance if max. number of connections is specified.
So again, its upto you to decide what all conditions are applicable to you. Its actually a trade-off between reliability and performance. :-)..
regards Stallon

Similar Messages

  • JSF DB Connection Best Practices

    During the life of a JavaServer Faces request, what are some best practices for storing a db connection?
    For the duration of the transaction, a single connection should be created before db updates, made available to (possibly) multiple model objects, and closed at the conclusion of the request. The connection would only live during the request.
    Right now each model object gets and releases it's own dbCon but that doesn't satisfy the (logical unit of work) requirements of a transaction when multiple objects are required for updating the database.
    What is a good technique to get a dbCon and release it, and, where should it be stored?
    TIA,
    Al Malin

    Hi,
    I'd like to ask a follow-up question.
    How do I close the connection after the session timed out or the user leaves the application by closing the browser?
    Thanks,
    Achim

  • External connectivity best practice

    Hi,
    I would like to know what are the best practices to have external users using Excel to connect to SSAS cube. I understand the general concept that a cube user must be in a domain AD andthat same user is a member of a SSAS cube.
    How can I ensure the excel connection is secure and each external user is only able to view their own data? I know the workbook can be password protected but can the connection be also password protected ?
    BTW, I am not sure if this is the right forum for this question
    Regards

    Most modern external drives will typically go into a standby mode shortly after they're unmounted or disconnected which will spin down the drive. They'll still use some power, but your drive won't be doing anything so you don't need to worry about wearing it out. I'm a bit anal about stuff. I usually go so far as to unplug my external drives when I'm not using them as the power supply still consumes some juice... but, in your case, as it seems like you probably go back and forth quite a bit... just powering it down would be the best thing. It really doesn't take any extra effort when connecting your MacBook Pro to just switch it back on again.

  • How to establish the connection - Best Practice

    Following is my code for database connection
    import java.sql.Connection;
    import java.sql.DriverManager;
    import oracle.jdbc.driver.OracleDriver;
    public class DBConnect
         private static Connection connection = null;
         static
              try
                   DriverManager.registerDriver( new OracleDriver() );
                   String url = "jdbc:oracle:thin:@dbserver:1521:ORCL";
                   connection = DriverManager.getConnection( url, "user", "password" );
              catch ( Exception e )
         private DBConnect()
         public static synchronized Connection getConnection()
              return connection;
    }Tell me the Best Practice to establish the connection.
    Edited by: shashiwagh on Feb 1, 2010 11:25 AM
    Edited by: shashiwagh on Feb 1, 2010 11:26 AM

    First, handle your exceptions properly.
    Second, you should not normally create static database connections.
    Third, hardcoding connection data like that is not a good idea.

  • Access Connections best practice

    I like the idea of having Lenovo Access Connection change the appropriate settings depending on you network location. Like turning off wifi when you are cabled.
    Althoguh I often find it to be creating more problems than gains.
    Any generel best practice using this tool?
    Regards, Lars.

    Hi!
    Use non overlapping channel 1-6-11 on 3
    consecutive AP's.
    eg.
    AP1-Channel 1
    AP2-Channel 6
    AP3-Channel 11
    AP4-Channel 1
    AP5-Channel 6
    plzz take a look:
    http://www.cisco.com/en/US/products/hw/wirele
    ss/ps441/products_tech_note09186a00800a86d7.shtml#nonover
    HTH
    -Jai

  • Managing connections best practices

    Hi,
    I have a web application that uses JDBC to retrieve information and display it. My question is: What is the best way to manage your connection objects? I know using a connection pool is probably best, but I'm curious to hear good alternatives? If I need a connection in several places in my web-app, then storing one Connection object in the session seems like a good idea. This way I don't have to create and close my connections each time and slow down performance. But what happens to the connection when the user is no longer in the session. Does the database close the connection implicitly and is there any cons to doing it this way?
    Thanks

    Hi,
    I have a web application that uses JDBC to retrieve
    information and display it. My question is: What is
    the best way to manage your connection objects? I know
    using a connection pool is probably best, but I'm
    curious to hear good alternatives? If I need a
    connection in several places in my web-app, then
    storing one Connection object in the session seems
    like a good idea. The term "session" usually refers to a 'space' that exists both on a client and a server.
    Connections never exist on more than one machine or even more than one application.
    This way I don't have to create and
    close my connections each time and slow down
    performance. But what happens to the connection when
    the user is no longer in the session. Does the
    database close the connection implicitly and is there
    any cons to doing it this way?
    Well one con is that in general you have no control over when the "session" is closed. Thus you must rely on finalize in a java class to close your connections via the GC. And unless you have a really unusual database, or you only use a couple of "sessions" an hour, you are going to run out of connections. This is because GC is optimized for memory handling and not any other resource (a connection is a resource.)

  • Physical Connection Best Practices

    Hi;
    I hope someone can help us.
    We already have 4 SG300 52 ports Switches: (L2 mode)
    We need to know the best way to connect the Switches and the router due to:
    - Do not get excesive latency in the internal network.
    - Do not get SPF problems.
    - Do not get duplicated pings
    - Get the maximum bandwith in the internal network.
    - Get the best router link.
    My thougts are:
    Option 1:
    Connect one uplink port to another uplink port at the next SW
    Connect the other uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 2
    Connect two uplink ports to the two uplink ports at the next SW
    Connect the number 1 port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 3 
    Connect two uplink ports to the number 1 and 2 port at the next SW
    Connect the uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Any suggestions?
    Thanks.
    Regards.

    If you have a multi-threaded server then before long you will have two "simultaneous" requests for a database connection. These requests will want to use different connections, since as you can see if they both use it at the same time, bad things will happen. You could synchronize so they wait in line to use the single connection but I think you can see that doesn't scale well to higher load.
    So you need to have access to more than one connection. What's commonly done in multi-threaded servers is to use a connection pool. You can get open-source connection pools, so don't spend any time writing your own. (They aren't easy to get right.)

  • Sql connection best practices

    Can someone discuss the pros and cons of setting your db connection in the web.xml and then using the following in a jsp;
    <sql:query var="myQuery">
         SELECT * FROM mytable
    </sql:query>I find that it is quick and easy, but would I want to give this kind of code to my supervisor? From 20,000 ft up. :)
    Edited by: Reme on Aug 2, 2008 5:12 AM

    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnald.html]
    The JSTL SQL tags for accessing databases listed in Table 7-7 are designed for quick prototyping and simple applications. For production applications, database operations are normally encapsulated in JavaBeans components.I wouldn't use it. Layer your application properly. Make use of a DAO class.

  • What is the best practice to connect 2 sites and replicate ADDS between 2 different sites using windows server 2012 r2?

    I found that there is new features remote access inside windows server 2012 r2 which is much more easier. Is there anybody can suggest me how to connect 2 different sites and it will be the tunnel to replicate ADDS (RW) between both sites.

    See this
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/133e7780-6a59-4bd7-906b-70830bea48d0/sites-connections-best-practice?forum=winserverDS
    Regards,
    Biswajit
    MCTS, MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, Enterprise Admin, ITIL F 2011
    Blog:
      Script Gallary:
      LinkedIn:
    Note: Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights..

  • Best practice for opening/closing JDBC conection

    I've written a program that accesses a database, and I'd like to know the best practice for opening and closing that connection. For example should I use a try{} finally {} block,
    try
        //load driver
        //create conection
        //create statement object
        //sql statement to execute
        //execute statement
    finally
        //close connection
    }Or should I split the code into seperate methods, maybe an init() method that loads the driver and makes the connection and an execute() method that creates the statement and executes it and finally a cleanUp() method that closes the connection.
    So, which would be the best way to do this?

    Hallo,
    your idea seems OK to me. However, there are a couple of points to consider:
    1. Do you just want to execute one SQL query? Or will your program execute several? If the latter case is possible, then you do not want to close your connection between queries. Opening and closing a connection to a database takes 'a lot of time', relatively speaking. In this case, it is better to save the connection and reuse it every time that you need it.
    2. Do not forget to close the statements and result sets that you create or get back from JDBC. Depending on the database (eg Oracle) that you are using, you can run out of cursors, and your application will stop.

  • Handling of connection closures, best practice

    Hello,
    I have the following situation (within some old code):
    Quite a lot of different values are stores in a ldap server and are fetched often from a long-running program. There are many child-contexts from the initialcontext. The two possiblities I see are:
    a) have one connection which handles all. Problem: When the connection is closed (by a ldap server restart or whatever) i have to reinitialise the initialcontext and all child contexts.
    b) i use connection pooling and use a new(pooled) connection for each query.
    Are the above assumtions correct? What would be the best practice to do this? Can Connection Request Controls help me with this?
    I'm quite new to the advanced things of JNDI and thank you in advance for your answers.
    cheers,
    Michael

    Yes, java.sql.SQLException is designed for that. It has two methods, getSQLState and getErrorCode, that will help you get the state of the RDBMS if something goes wrong. - MOD

  • Error while Connecting report Best Practices v1.31 with SAP

    Hello experts,
    I'm facing an issue while trying to connect some of my reports from Best Practices for BI with SAP.
    It only happens when it's about info sets, the other ones that are with SAP tables go smoothly without a problem.
    The most interesting is I have already one of the reports connected to SAP info sets.
    I have already verified the document of steps of creation of additional database that comes with BP pack. They seem ok.
    Here goes what Crystal Reports throws to me after changing the data source to SAP:
    For report "GL Statement" one of the Financial Analysis one which uses InfoSet: /KYK/IS_FIGL_I3:
    - Failed to retrieve data from the database; - click ok then...
    - Database connector error: It wasn't indicated any variant for exercise (something like this after translating) - click ok then
    - Database connector error: RFC_INVALID_HANDLE
    For report "Cost Analysis: Planned vs. Actual Order Costs" one of the Financial Analysis one which uses InfoSet: ZBPBI131_INFO_ODVR and ZBPBI131_INFO_COAS; and also the Query CO_OM_OP_20_Q1:
    - Failed to retrieve data from the database; - click ok then...
    - Database connector error: check class for selections raised errors - click ok then
    - Database connector error: RFC_INVALID_HANDLE
    Obs.: Those "Z" infosets are already created in SAP environment.
    The one that works fine is one of the Purchasing Analysis reports:
    - Purchasing Group Analysis -> InfoSet: /KYK/IS_MCE1
    I'm kind of lost to solve this, because I'm not sure if it can be in the SAP JCO or some parameter that was done wrongly in SAP and I have already check possible solutions for both.
    Thanks in advance,
    Carlos Henrique Matos da Silva - SAP BusinessObjects BI - Brazil.

    I re-checked step 3.2.3 - Uploading Crystal User Roles (transaction PFCG) - of the manual where it talks about CRYSTAL_ENTITLEMENT and CRYSTAL_DESIGNER roles, I noticed in the Authorizations tab that the status was saying it hadn't been generated and I had a yellow sign, so then that was what I did (I generated) as it says in the manual.
    Both statuses are now saying "Authorization profile is generated" and the sign is now green on the tab.
    I had another issue in the User tab (it was yellow as Authorizations one before generating)....all I needed to do to change to green was comparing user (User Comparison button).
    After all that, I tried once more to refresh the Crystal report and I still have the error messages being thrown.
    There's one more issue in one of the tabs of PFCG transaction, it is on the Menu one where it is with a red sign, but there's nothing talking about it in the manual. I just have a folder called "Role menu" without anything in it.
    Can it be the reason why I'm facing errors when connecting the report to SAP infoSets? (remember one of my reports which is connected to an infoSet works good)
    Thanks in advance,
    Carlos Henrique Matos da Silva - SAP BusinessObjects BI - Brazil.

  • BEST PRACTICES FOR CREATING DISCOVERER DATABASE CONNECTION -PUBLIC VS. PRIV

    I have enabled SSO for Discoverer. So when you browse to http://host:port/discoverer/viewer you get prompted for your SSO
    username/password. I have enabled users to create their own private
    connections. I log in as portal and created a private connection. I then from
    Oracle Portal create a portlet and add a discoverer worksheet using the private
    connection that I created as the portal user. This works fine...users access
    the portal they can see the worksheet. When they click the analyze link, the
    users are prompted to enter a password for the private connection. The
    following message is displayed:
    The item you are requesting requires you to enter a password. This could occur because this is a private connection or
    because the public connection password was invalid. Please enter the correct
    password now to continue.
    I originally created a public connection...and then follow the same steps from Oracle portal to create the portlet and display the
    worksheet. Worksheet is displayed properly from Portal, when users click the
    analyze link they are taken to Discoverer Viewer without having to enter a
    password. The problem with this is that when a user browses to
    http://host:port/discoverer/viewer they enter their SSO information and then
    any user with an SSO account can see the public connection...very insecure!
    When private connections are used, no connection information is displayed to
    SSO users when logging into Discoverer Viewer.
    For the very first step, when editing the Worksheet portlet from Portal, I enter the following for Database
    Connections:
    Publisher: I choose either the private or public connection that I created
    Users Logged In: Display same data to all users using connection (Publisher's Connection)
    Users Not Logged In: Do no display data
    My question is what are the best practices for creating Discoverer Database
    Connections.
    Is there a way to create a public connection, but not display it in at http://host:port/discoverer/viewer?
    Can I restrict access to http://host:port/discoverer/viewer to specific SSO users?
    So overall, I want roughly 40 users to have access to my Portal Page Group. I then want to
    display portlets with Discoverer worksheets. Certain worksheets I want to have
    the ability to display the analyze link. When the SSO user clicks on this they
    will be taken to Discoverer Viewer and prompted for no logon information. All
    SSO users will see the same data...there is no need to restrict access based on
    SSO username...1 database user will be set up in either the public or private
    connection.

    You can make it happen by creating a private connection for 40 users by capi script and when creating portlet select 2nd option in Users Logged in section. In this the portlet uses there own private connection every time user logs in.
    So that it won't ask for password.
    Another thing is there is an option of entering password or not in ASC in discoverer section, if your version 10.1.2.2. Let me know if you need more information
    thnaks
    kiran

  • What are the best practices to connect 30-40 iPads to Wi-Fi in a single room?

    What are the best practices to connect 30-40 iPads to Wi-Fi in a single room?

    I don't use it but it does say this in the help section...

  • [XI 3.1] BEST PRACTICE method of Oracle connection for RPTs on Linux

    Business Objects XI (3.1) - SP3.
    Running on Red Hat Enterprise Linux OS.
    7,000+ Crystal Reports 2008 *.rpt objects ONLY (No Universe / No WebI).
    All reports connecting to Oracle 10g databases.
    ==================
    In the past, all of this infrastructure was running on Windows Server OS and providing the database access via a Named ODBC connection (eg. "APP_DATA".)
    This made it easy to manage as all the Report Developers had a standard System DSN called "APP_DATA" which was the same as the System DSN name on all of our DEV, TEST/UAT, and PROD servers for Business Objects.
    When we wanted to move/promote a *.rpt file from DEV to PROD we did not have to change any "Database Connection" info as it was all taken care of by pointing the System DSN called "APP_DATA" a a different physical Oracle server at the ODBC level.
    Now, that hardware is moving from Windows OS to Red Hat Linux and we are trying to determine the Best Practices (and Pros/Cons) of using one of the three methods below to access the Oracle database for our *.rpts....
    1.) Oracle Native connection
    2.) ODBC connection
    3.) JDBC connection
    Here's what we have determined so far -
    1a.) Oracle Native connection should be the most efficient method of passing SQL-query to the DB with the fewest issues and best speed [PRO]
    1b.) Oracle Native connection may not be supported on Linux - http://www.forumtopics.com/busobj/viewtopic.php?t=118770&view=previous&sid=9cca754b468fc67888ab2553c0fbe448 [CON]
    1c.) Using Oracle Native would require special-handling on the *.rpts at either the source-file or the CMC level to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    2a.) A 3rd-Party Linux ODBC option may be available from EasySoft - http://www.easysoft.com/products/data_access/odbc_oracle_driver/index.html - which would allow us to use a similar Developer / Admin overhead to what we are used to. [PRO]
    2b.) Adding a 3rd-Party Vendor into the mix may lead to support issues is we have problems with results or speeds of our queries. [CON]
    3a.) JDBC appears to be the "defacto standard" when running Oracle SQL queries from Linux. [PRO]
    3b.) There may be issues with results or speeds of our queries when using JDBC. [CON]
    3c.) Using JDBC requires the explicit-IP of the Oracle server to be defined for each connection. This would require special-handling on the *.rpts at either the source-file (and NOT the CMC level) to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    ==================
    We would appreciate some advice from anyone who has been down this road before.
    What were your Best Practices?
    What can you add to the Pros and Cons listed above?
    How do we find the "sweet spot" between quality/performance/speed of reports and easy-overhead for the Admins and Developers?
    As always, thanks in advance for your comments.

    Hi,
    I just saw this article and I would like to add some infos.
    First you can quite easely reproduce the same way of working with the odbc entries by playing with the oracle name resolution on the server. By changing some files (sqlnet, tnsnames.ora,..) you can define a different oracle server for a specific name that will be the same accross all environments.
    Database name will be resolved differently regarding to the environment and therefore will access a different database.
    Second option is the possibility to change the connection in .rpt files by an automated way like the schedule manager. This tool is a additional web application to deploy that can change the connection settings of rpt reports on thousands of reports in a few clicks. you can find it here :
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80af7965-8bdf-2b10-fa94-bb21833f3db8
    The last option is to do it with a small sdk script, for this purpose, a few lines of codes can change all the reports in a row.
    After some implementations on linux to oracle database I would prefer also the native connection. ODBC and JDBC are deprecated ways to connect to database. You can use DATADIRECT connectors that are quite good but for volumes you will see the difference.

Maybe you are looking for

  • ITunes will not recognize my iPod Touch 4 so I am not able to restore

    I am trying to restore my iPod Touch 4th Generation so I can get rid of the jailbreak but whenever I plug in my device, the computer recognizes it but not iTunes. I have managed to get it to recognize it a few times which is when I try to restore it,

  • Why use "Don't Color Manage This Document"?

    Hello, I work on photos, mostly black and white, that will be either digitally or offset printed. I have been told that I should not assign any color profile to these photos in PhotoShop. I should instead choose the option in Assign Profile to "Don't

  • Resizing photos for a website?

    I a building a website and when I resize -- even to make a photo or logo smaller -- everything gets wavy and low-quality.  Help!

  • Problems installing photoshop and other adobe products

    hey! i recently make a clean windows install. (xp pro) and wen i try to instal photoshop cs3, i run the setup.exe but nothing happens, so i cant make it work, and with illustrator cs5, i was able to make the install, but when i try to run it it says

  • Audio package install

    Dears, i am new user in solaris i am using solaris 10 [Audio Drivers 1.0 for Solaris 10 - x86|https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_SMI-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=Sol-audio-drivers1.0-x86-G-F@CDS-CDS_SMI]