Solved

Using a single connection to a MSSQL database

Posted on 1997-09-16
1
183 Views
Last Modified: 2010-04-04
I'm trying to write an application that uses a single connection to a MSSQL database server, for all its queries.

I'm currently pointing all my TTable objects at single TDatabase object. But what I find is that each time I open a new TTable it makes a new connection to the database server. So for example, on one form I need 5 TTable open at the same time, and hence I get 5 connections. What I would like is to use only one connection for all 5 TTables.

Is there a way to do this, and if there is what is it?
0
Comment
Question by:belgan
1 Comment
 
LVL 1

Accepted Solution

by:
anilms earned 100 total points
ID: 1345008
Yes, you can do it. Assuming that you are connecting your TTable component to different DB Aware controls such as grids and edits in different forms, you can have one single TTable and DataSource in the main form. During run time, you can change the following properties to connect to different tables through the same connection:

First make the tables's active property false.
Change the Table name to the new table name
Then make the table's active property true.

I would , however, suggest that you use the TQuery component instead. In fact you are supposed to use TQuery component when you are working with SQL databases. Then you will not have this problem of new connections.  The TQuery component is used just like the TTable component, the difference being you enter the SQL property and then execute it. The TQuery component then fills up your data aware connected controls such as dbEdit and dbGrid.

If you still have further problems, please contact me thro email at anil_ms@hotmail.com
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question