Keep Connection Or Close & Re-open?
I have a VB app that allows up to 10 clients to access an Access 97 db (typically about 50 meg in size) on an NT server. Each client opens one connection to the database and the connection remains open as long as the app is running. The app typically needs to create and close many recordsets.
Anyone have an opinion as to whether this is a poor practice? If so, what problems might it cause. Also, what effects might I see if I continually open and close connections as they are needed?
(using DAO now but am currently upgrading to ADO)
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
- Close, Set, OPEN.....connection...
- How Often Should I Open/close A Connection To A DB
- When To Open/close A Connection
- Open And Close Adodb.connection
- ADO Connection - Leave Open Or Close?
- Database Connection Open And Close
- Keep Database Connection Open Or Close?
- Please Give Me Statements Of Sql DB's Connection, Open, Update, Close
- Best Practice: One Global Database Connection Or Open/close As Needed?
- Close Recordset Or Close Connection?
- Close Connection/close Database
- Should I Have 100s Of Winsock Connections Open/close.. Or Keep Them Open (hard Q)?
- Open An Excel Worksheet, Close It, Perform Cleanup And Open It Again - Can't Do It
- Difference Between Connection.close And Set Connection=nothing
- Connection Begintrans Cannot Close The Connection
- Open A File, Close It, Open Next.
- Open A File, Close It, Open Next.
- Close Connection
- Close Connection
- Close Connection
- Close An ADO Connection
- Close Connection
- Close Connection
- Close Connection
- How To Close The Connection
- Connection Close?
- Open...whats Open? Record Connection?
- Why Can't I Close A Connection With The Datagrid?!?!?
- Close Connection Of Foxpro From VB
- How To Close FTP Connection Using Inet
- Close Connection DataEnvironment
- How To CLOSE An ADODC Connection
- How To Close Adodc-connection
- When To Close The Connection And Recordset?
- Help To Close The Connection With Database
- Can't Close Winsock Connection
- How To Close A Dial Up Connection
- Can't Close A DataEnv Connection
- How Do I Close An Internet Connection?
- How To Close Adodc Connection?
- Problem With Close Connection...
- How To Close A Socket Connection?
- How To Close The Connection Of Adodc
- Close A ADODC Connection
- Close A Inet Control Connection
- Connection Close Causes Errorless Crash.
- Close DB Connection (Type Mismatch)
- Unable To Perform Db Connection Close
- Failed To Close Socket Connection
Close, Set, OPEN.....connection...
head fired!!!!!!!!
When i click on button4 (this button UPGRADE record in mdb) have this message:
"opearation not possible if object is open....." error 3705
WHY!!!!!!
How Often Should I Open/close A Connection To A DB
Hello
I am creating a small application in VB/Access. The application creates a Db of Client names, project names and time spent working on each project.
During the execution of the program I access the DB many times
ie to add a new project I have to get a client ID from the DB based on the Client name then update the project table with the project name, client id and have the DB generate a project ID. I then get the project ID and display it on the screen. During this process I open and close the connection to the DB each time I 'go to it'
My question
What is considered to be better programming style. To open and close the connection each time I access the DB or to keep the connection open until the entire process is complete?
The DB and appliction will reside on the users PC . In other words the DB will not be placed on a server. Does this factor into the question mentioned above
When To Open/close A Connection
Scenario:
3-tier application.
Database : SQL server or Oracle
Users : 20 users
Each user starts the application and uses the application atleast 8hrs. a day.
I'm having a confusion when to open/close the connection like...
Open connection when the application starts and
Close connection When the application exists.
Open connection within a method and close connection at the end of each method and use connection pooling using MTS.
Basically i'm thinking of following the first method as the user always does a lot of database operations atleast 2 database request/min. all over the day. So there is no need of closing the connection and opening it again.
Please give me suggestion.
Thanks in advance
-Venky
Open And Close Adodb.connection
Hi, I've written a vb app that uses adodb.connection object for updates and deletes and recordset object for returning data. My question is this, the program is designed to run for weeks at a time (its an SMTP server). I have a class file for my database connections and queries, at Class_Initialize() (called on frmMain.form Load()) I open the connection and don't close it until Class_Terminate() which could be a month later. It this the most efficient way to utilize a connection? In the past I opened and closed the connection with each use of the database class. There are mutliple calls to the class (could be ten thousand an hour) so I thought a single open and close would be best.
Any thoughts on this?
ADO Connection - Leave Open Or Close?
My applications back end is a SQL Server 2000 database.. so I was going to change my code over from
open connection
open recordset
do stuff
close recordset
close connection
to
* open connection when app starts
open recordset when needed
do stuff
close recordset when done
* close connection when app ends
it seems the performance gain would be decent if the connection is left constant... only about 50 users connect at any given time.. so i dont think it will become an issue where too many people are connected to the server.. i know SQL Server can handle a great deal of connections... this app used to run off of an access database which is why its coded the way it is...
Database Connection Open And Close
Hello
my program uses OLE DB to SQL server and sometimes i call a stored procedure via the dataenvironment.
in some cases i have noticed that i need to open the connection when i execute a stored procedure and sometimes i don't have do open it.
Does anybody now if I always should open the connection before a execute a Stored Procedure or if you dont need to do it because it automaticlly opens it ?
It also takes some time to open the connection everytime before i execute a SQL string.
could i do this in a better way ?
i dont want to have the connection open all the time.
thanks in advance
Micke
Keep Database Connection Open Or Close?
Hi,
I'm writing a program for college using VB6 and ADO connecting to SQL Server 2000 Database. The program is going to be a booking system with no more than 5 people accessing the database at the same time.
Should I open a connection to the database on application loading and close the connection when application closes or open the connection when reading from and writing to the database?
Best Practice: One Global Database Connection Or Open/close As Needed?
General "Best Practices" Question:
I've got a program that I'm writing in VB 6.0 using MSDE. The program will be listening for MSComm events that vary in their occurances. Sometimes they will happen 10 - 15 times a minute, sometimes nothing for 5 or 6 hours (maybe even a couple of days). When they happen, I have to input the incoming data into the appropriate MSDE tables.
My question is what is the better approach to handling the MSDE connection? Right now I'm writing it so that each time the Procedure is fired it declares the connection, opens it, runs the stored procedure, inputs the recordset into a Flexgrid, then closes the recordset and connection and sets connection, recordset and command objects all to Nothing. Would it be better, on Form_Load, to open the connection and just leave it open? Then when an event is fired just declare the recordset and command and then move on from there?
If I knew that the updates would only be happening very infrequently then I'd go with open/close. But sometimes they will happen very often so that could become somewhat time consuming.
How would you guys handle something like this?
Here's what I have so far:
Code:
' procedure that is run
Public Sub GetUpdateList()
If boolShowFG = True Then
Dim cmdShowUpdate As ADODB.Command: Set cmdShowUpdate = New ADODB.Command
Dim conShowUpdate As ADODB.Connection
Dim rsShowUpdate As ADODB.Recordset: Set rsShowUpdate = New ADODB.Recordset
' open the connection
Set conShowUpdate = New ADODB.Connection
conShowUpdate.ConnectionString = "Provider=sqloledb; Data Source=MyMachineMyInstanceName; Initial Catalog=MyDatabase; User Id=User; Password=Password"
conShowUpdate.CursorLocation = adUseServer
conShowUpdate.Open
With cmdShowUpdate
.CommandText = "sp_GetUpdateList"
.CommandType = adCmdStoredProc
Set .ActiveConnection = conShowUpdate
End With
Set rsShowUpdate = cmdShowUpdate.Execute
If (Not rsShowUpdate.BOF) Or (Not rsShowUpdate.EOF) Then
' run code to populate Flexgrid
Else
' hide Flexgrid
flexUpdate.Visible = False
End If
rsShowUpdate.Close
conShowUpdate.Close
Set cmdShowUpdate = Nothing
Set rsShowUpdate = Nothing
Set conShowUpdate = Nothing
Else
Exit Sub
End If
End Sub
' Stored Procedure
CREATE PROCEDURE sp_GetUpdateList
AS
SET NOCOUNT ON
DECLARE @Error AS Integer
SELECT Top 10 * FROM tblUpdates ORDER BY upID DESC
Now, that is just one procedure. Before it gets to this one, there is another that queries 3 tables in the database for specific information on that update (customer name, etc.). Actually, it's (the first procedure) 3 queries that happen before it gets to here. Eventually I'm going to want to put all of that into "triggers" (I think that's what they are called) so that I don't have to run 3 queries (from my application, at least). Right now the one you see above is the only one utilizing a Stored Procedure (I'm in the process of writing the rest that way).
Actually, I'm not even sure if this is the best approach (in terms of setting up the connection, getting the recordset, etc.). I know there is a LOT I need to add in terms of the Stored Procedure (checking that it ran OK, making sure there's no errors, etc.). This Stored Procedure isn't looking for any input parameters, it's just returning the last 10 updates. As you can see, I'm barely scratching the surface and have probably messed things up already. I got the procedure (well, part of it) from another post in one of the threads here I believe. Anyway, when it comes to return parameters and outputs and input, I'm still learning (and still confused).
But my question for now is the connection thing. What would, in your opinions, be the best approach?
Thanks in advance for any help and/or assistance you can give me. It is very much appreciated.
DTFan
Ever-hopeful programmer-in-training
Edited by - DTFan on 11/16/2005 9:36:05 AM
Close Recordset Or Close Connection?
I have a recordset and connection I open up, and then I have another recordset from a different table I want to open. Do I need to close the previous connection or recordset? I saw this somewhere but I can't remember. Thanks!
Heres my code so far. You can see at the bottom my feeble attempt at opening a second recordset from a different table.
Option Explicit
Dim Ordernumber As String
Private Sub cmdFind_Click()
Ordernumber = txtOrdernumber.Text
'' Connection to ODBC Start
lblStatus.Caption = "Connecting to MAS90 ODBC"
Dim Mas90 As ADODB.Connection
Dim rstMyrecset As ADODB.Recordset
Dim cmdMyrecset As ADODB.Command
Dim rstmyrecset2 As ADODB.Recordset
Dim cmdmyrecset2 As ADODB.Command
Dim strResults As String
Dim strResults2 As String
Set Mas90 = New ADODB.Connection
Mas90.ConnectionString = "dsn=sotamas90"
Mas90.Open
lblStatus.Caption = "Connection Successful."
'' Connection to ODBC End
Set cmdMyrecset = New ADODB.Command
cmdMyrecset.ActiveConnection = Mas90
cmdMyrecset.CommandText = "SELECT SalesOrderNumber, LinkToFirstDetailRecord FROM SO1_SOEntryHeader"
Set rstMyrecset = cmdMyrecset.Execute
rstMyrecset.Find "SalesOrderNumber LIKE '" & Ordernumber & "'", 1, adSearchForward
strResults = rstMyrecset.Fields.Item("SalesOrderNumber").Value
txtResults.Text = strResults
strResults2 = rstMyrecset.Fields.Item("LinkToFirstDetailRecord").Value
txtResults2.Text = strResults2
Set cmdmyrecset2 = New ADODB.Command
cmdMyrecset.ActiveConnection = Mas90
cmdMyrecset.CommandText = "SELECT LinkToPrevLine FROM SO2_SOEntryDetailLine"
Set rstmyrecset2 = cmdmyrecset2.Execute
End Sub
Close Connection/close Database
I am creating an Access database in VB and opening it with ADO. I create and populate a table, and do whatever I need to do with table. I want to then go back several steps and Kill the database so I can recreate it and populate a new table (same name as before, different data). WhenI go to kill the database, I get a permission denied because the ldb still exists. When is the database closed, i.e., the ldb ceases to exist? Is it when I close the connection? If not, how can I explicitly close the database so I can delete it?
Set cnPointDB2 = New ADODB.Connection (i've already dim'd it)
With cnPointDB2
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open "C:Analysis.mdb"
End With
With this, analysis.ldb is created.
When I am finished I close the connection and set cnPointDB2 = nothing before trying to kill it.
I must admit that I do open this database in a few places to do different things at various times before I need to kill it. Could it be that a connection is still open from a different part of the code and causing me a problem? I did find a post from last year about opening a db once (in a multiuser environment, which my application is not) and leaving it open versus opening and closing it as needed.
Should I Have 100s Of Winsock Connections Open/close.. Or Keep Them Open (hard Q)?
Hello
Ive got a server to which many clients connect to.
They each are given a few tasks to complete - which may or may not take a long time to finish, and after each task is done they send back the result.
This has caused massive amounts of problems for me. Right now I keep the connections open all the time. My server listens on one particular winsock control on a particular port to which all clients connect. It then accepts the connection request thru a second array of winsocks, so each client is connected to the server via the array via one connection.
There is generally no problem sending out the tasks thru that single connection/client - but receiving is a problem. The client may need to send back a few hundred kb at a time but since it was completing several tasks at once - it is not always received correctly. My guess is because taskA is sending data thru the connection at the same time as taskB - and the data isnt received right (each task sends its data via a <start> and an <end> string so I know where the start/end of data is and when transmission is over). Its important to note that the tasks are multithreaded (via a 3rd party control)
The data is sent in one line per task. winsock.SendData theResult. But many tasks can complete at around the same time. I thought that VB would wait until the data was completely sent (for one lines code) before moving on... but I dont think this is happening. I even tried adding a DoEvents but to no avail - I still cant receive the data properly. Maybe winsock is 'skipping over' some data - I dont know. (Kinda like when if you 'break' the application winsock does not get incoming data and when you resume it still wont pick it up)
So Ive got 2 options..
1) Somehow figure out how to receive data properly when multiple tasks finish on a client at around the same time and they send data at the same time - basically making the program send the data of a task and not continue until the data has been sent, then send another tasks data.
2) Use many connections. Basically the max # of tasks running at once will be about 10. So the idea is to have another winsock array of 10, each dedicated to one task, and when a task is completed - connect thru the winsock array, send the data, and when the server receives it - it disconnects.
3) A mixture of 1 and 2 - have the 10 winsocks connect to the server and be open at the same time, then I can just send data and receive via a specific winsock array control and there is no problem distinguishing taskA from taskB from taskC on a client, or client from client.
But honestly.. I dont know if its 'bad' to have lots of connections open and close all the time. And I dont know if its 'bad' to have thousands of connections open at the same time either..
What do you guys think?
Connection Begintrans Cannot Close The Connection
Hi,
Im doing a program using vb6 to connect with access 2000 now.
I'm facing problem with the begintrans and rollbacktrans connection issue.
i have two table header and details table, the program let user to insert multiply line in the details table.
i use the connection.begintrans and connection.committrans to update both table when user finish add in multiply line record.
i'm using 2 recordset to query header and details table.
then i user recordset.addnew to add in multiple line in the details table.
when user execute the save button, i will call the recordset.updatebatch and connection.commitrans.
my problem is when the user insert several line in details and want to create a new record, i need to call the connection.rollbacktrans to clear the previous record in header and details table.
after i call the rollbacktrans, and i want to close the connection object. the system prompt out a error message as below:
run time error 3246 connection object cannot be explicitly closed while in transaction
why i can not close the coonection after i call the rollbacktrans.
adodcCon.BeginTrans
adodcTrxHdr.AddNew
adodcTrxHdr("TRX_DATE") = dtpTrxDate.Value
adodcTrxHdr("TRX_CODE") = txtTrxNo.Text
adodcTrxHdr("CUST_CODE") = txtCustomerCode.Text
adodcTrxDtl.AddNew
adodcTrxDtl("TRX_DATE") = dtpTrxDate.Value
adodcTrxDtl("TRX_CODE") = txtTrxNo.Text
adodcTrxDtl("TRX_LINE_NO") = iTrxLineNo
adodcTrxDtl("COUPON_CODE") = ""
adodcTrxDtl("UNIT_PRICE") = txtUnitPrice.Text
adodcTrxDtl("ITEM_CODE") = txtItemCode.Text
adodcTrxDtl("CUR") = lblCurrency.Caption
adodcTrxDtl("QTY") = txtQuantity.Text
adodcTrxDtl("TOTAL") = txtUnitPrice.Text * txtQuantity.Text
adodcTrxHdr.CancelUpdate
adodcTrxDtl.CancelUpdate
adodcCon.RollbackTrans
what's wrong with my code here ? can someone teach me on how to solve this ? or is there any other idea to solve this issue using other method than using begin trans???
urgent .. thanks for the help...
Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?
Thanks in advance.
-Jer
Open A File, Close It, Open Next.
I've got my searching code going now, but I'm looking for a way to tell the program to load each file in a directory, one at a time, search, close it, move on to the next. And I have no clue how to do that. Any ideas?
Thanks in advance.
-Jer
Close Connection
To connection to my database I use the code below but I can't work out how to disconnect from it. Can someone help me out? Thanks
Code:
Dim strCn as String
strCn = ConnectString()
Code:
Public Function onnectString() As String
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" & App.Path & "My DBName.mdb"
End Function
Close Connection
My computer need to communicate with another computer over the local LAN.I can setup the connection but i have problem closing the connection...meaning my computer is still connected to the remote comp even after i exit the application
the function i used is:CloseConn (LocalDrive$)
what should i specify inside ()??
Close Connection
To connection to my database I use the code below but I can't work out how to disconnect from it. Can someone help me out? Thanks
VB Code:
Dim strCn as StringstrCn = ConnectString()
VB Code:
Public Function onnectString() As StringConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _ "Data Source=" & App.Path & "My DBName.mdb"End Function
Close An ADO Connection
As a DB developer, you'd think that I'd know the answer to this but it always has seemed to have eluded me!
I want to use a ADO control to return some fields in a drop down list (EASY BIT). But then I want to close the connection.
I think it is something to do with the locktypes but my mind is a complete blank about it. Note: The dropdowns are bound to the ADO
Can anyone help? Even to say if it can be done or not!
Thanks
simlee
Close Connection
how do i disconnect or end connection to the internet at a set time?
thanks
Brian
Close Connection
Hi Everyone,
I am using this form to run a sql statement.
Code:
Connection.Execute "UPDATE Table SET Field1 = '" & NewItem & "'"
However, sometimes when I try to run this sql statement again right after having finished running it the first time I get this error message.
Object block or with variable block not set.
Does anyone know what is causing this error to keep poping up? I would appreciate any help. Thank you.
How To Close The Connection
Hi there
I have this piece of code
Code:
Code:
Dim Conn As New ADODB.Connection
On Error GoTo Errorhandler
Conn.ConnectionString = strdsn
Conn.Open
Conn.BeginTrans
'...some insert etc statements here
conn.execute query
Conn.Close
Errorhandler:
strErr = strErr + Err.Description
If Conn.State = 0 Then
End If
If Conn.State = 1 Then
Conn.Close
End If
This doesnt include the situation when the transaction is open if it errors out
Can someone help me out
Connection Close?
I have a program in client side use winsock to make connection with a streaming
server. However, somtimes it will disconnect. So, is there any method
to check that if the connection is close and reconnect to server immediately?
Thanks!
Open...whats Open? Record Connection?
I have some code and it keeps dying on the line:
objRSTC.ActiveConnection = Nothing
The complete code is long:
VB Code:
Private Sub CopyTransports(lngProposalID As Long)On Error GoTo Err_Handler Dim objCmd As ADODB.CommandDim objRS As ADODB.Recordset 'for transportsDim objRSTC As ADODB.Recordset 'for transport componentsDim lngOldTransportID As LongDim lngNewTransportID As Long Call EstablishConnectionSet objCmd = New ADODB.CommandobjConn.CursorLocation = adUseClient 'first we snatch current proposal's transports'the one we are looking at... With objCmd .ActiveConnection = objConn .CommandText = "select_transports_by_proposal" 'our stored procedure is good_login .CommandType = adCmdStoredProc 'its a stored procedure .Parameters.Append .CreateParameter("ProposalID", adInteger, adParamInput, , lngProposalID) Set objRS = .Execute objRS.ActiveConnection = Nothing Call ReleaseConnection End With If objRS.BOF Then 'no records? Exit Sub Else If objRS.EOF Then Exit Sub Else Call EstablishConnection While Not objRS.EOF 'we loop through each transport Set objCmd = Nothing Set objCmd = New ADODB.Command 'grab the old transportid lngOldTransportID = objRS("TransportID").Value 'create the new transport With objCmd .ActiveConnection = objConn .CommandText = "insert_transport" 'our stored procedure is good_login .CommandType = adCmdStoredProc 'its a stored procedure .Parameters.Append .CreateParameter("TransportID", adInteger, adParamReturnValue) .Parameters.Append .CreateParameter("ProposalID", adBigInt, adParamInput, , NewProposalID) 'transport will get newest proposal id that was just created .Parameters.Append .CreateParameter("TDescription", adLongVarChar, adParamInput, SizeOfSQLText, objRS("TDescription").Value) .Parameters.Append .CreateParameter("TFunction", adLongVarChar, adParamInput, SizeOfSQLText, objRS("TFunction").Value) .Parameters.Append .CreateParameter("TAssumption", adLongVarChar, adParamInput, SizeOfSQLText, objRS("TAssumption").Value) .Parameters.Append .CreateParameter("TEndPos", adSmallInt, adParamInput, , objRS("TEndPos").Value) .Parameters.Append .CreateParameter("CreatedBy", adVarChar, adParamInput, 30, objRS("CreatedBy").Value) .Parameters.Append .CreateParameter("CreatedOn", adDate, adParamInput, , objRS("CreatedOn").Value) .Execute 'grab the new transport id lngNewTransportID = .Parameters("TransportID").Value 'whats the TransportID? End With 'now we have to do this components transports...that is we 'first search for oldtransportid's components 'if they are found they are inserted for the 'newtransportid's component 'so first we find oldtransportid's components Set objCmd = Nothing Set objCmd = New ADODB.Command With objCmd .ActiveConnection = objConn .CommandText = "select_transport_components_by_transport_id" 'our stored procedure is good_login .CommandType = adCmdStoredProc 'its a stored procedure .Parameters.Append .CreateParameter("TransportID", adBigInt, adParamInput, , lngOldTransportID) Set objRSTC = .Execute objRSTC.ActiveConnection = Nothing Call ReleaseConnection End With 'we have found the old transportid's components 'so now we have to add the transport components to the newest transportid If objRSTC.BOF Then 'no records Else Call EstablishConnection While Not objRSTC.EOF Set objCmd = Nothing Set objCmd = New ADODB.Command With objCmd .ActiveConnection = objConn .CommandText = "insert_transport_component" .CommandType = adCmdStoredProc 'its a stored procedure .Parameters.Append .CreateParameter("TCompID", adInteger, adParamReturnValue) .Parameters.Append .CreateParameter("TransportID", adBigInt, adParamInput, , lngNewTransportID) .Parameters.Append .CreateParameter("AdditionalDescription", adLongVarChar, adParamInput, SizeOfSQLText, objRSTC("AdditionalDescription").Value) 'TComp holds the TXXX number .Parameters.Append .CreateParameter("TComp", adVarChar, adParamInput, IIf(Len(objRSTC("TComponent").Value) < 1, 50, Len(objRSTC("TComponent").Value)), objRSTC("TComponent").Value) .Parameters.Append .CreateParameter("TCompDescription", adVarChar, adParamInput, IIf(Len(objRSTC("TComponentDescription").Value) < 1, 1000, Len(objRSTC("TComponentDescription").Value)), objRSTC("TComponentDescription").Value) .Parameters.Append .CreateParameter("Quantity", adInteger, adParamInput, , objRSTC("Quantity").Value) .Parameters.Append .CreateParameter("N", adInteger, adParamInput, , objRSTC("N").Value) .Parameters.Append .CreateParameter("TCPos", adInteger, adParamInput, , objRSTC("TCPos").Value) .Parameters.Append .CreateParameter("CreatedBy", adVarChar, adParamInput, 30, objRSTC("CreatedBy").Value) .Parameters.Append .CreateParameter("CreatedOn", adDate, adParamInput, , objRSTC("CreatedOn").Value) .Execute End With objRSTC.MoveNext Wend End If 'end if objRSTC.bof then objRS.MoveNext Wend End If End If Done:Set objCmd = NothingSet objRS = NothingSet objRSTC = NothingExit Sub Err_Handler:MsgBox Err.Description, vbCritical, "Error #: " & Err.NumberResume Done End Sub
Pay close attention to where its happening though:
VB Code:
'so first we find oldtransportid's components Set objCmd = Nothing Set objCmd = New ADODB.Command With objCmd .ActiveConnection = objConn .CommandText = "select_transport_components_by_transport_id" 'our stored procedure is good_login .CommandType = adCmdStoredProc 'its a stored procedure .Parameters.Append .CreateParameter("TransportID", adBigInt, adParamInput, , lngOldTransportID) Set objRSTC = .Execute objRSTC.ActiveConnection = Nothing Call ReleaseConnection End With
The error is:
[error]
Operation is not allowed when the object is open?
[error]
Not sure why?
Jon
Why Can't I Close A Connection With The Datagrid?!?!?
I get a recordset from my database with a sql statement and I set the datasource of the datagrid to my recordset. If I leave the connection open everything works fine If I close it nothing comes up in the data grid
heres where I am is it how I'm opening it?!?!?!
oconn.open
strsql = "select * from mydb where [ids] = '" & idnums.text & "'"
with rsgetit
.cursorlocation = aduseclient
.open strsql,oconn,,,adcmdtable
end with
set datagrid.datasource = rsgetit
is there no way to close a connection with the datagrid?!?!
Close Connection Of Foxpro From VB
Im using vfoxpro database on vb. i could do everything in the database, the problem is when im closing the database and try to copy the file to another filename, an error occurs. this also happens when i had pack a database then close the connection, when i open a new foxpro database using the same(or even a new connection), an error still occur. it seems that when i open a database using a adodb connection, even if i had closed it and set the connection as "nothing", the database might still be loaded on the memory.
How To Close FTP Connection Using Inet
this is how im connecting..
Code:
With Inet1
.Cancel
.Protocol = icFTP
.URL = "ftp://webpages.webpages.net"
.UserName = "username"
.Password = "password"
End With
but i just realized that im not closing this connection... would i use the .cancel?
Code:
Inet1.Cancel
or do i even need to close it?
also why am i using the . Cancel here?
Code:
With Inet1
.Cancel
thanks
Close Connection DataEnvironment
I've a little problem with the dataEnvironment... one time used DE and DReport I try to delete the db but the system answer me that the db is opened in exclusive mode by the admin user... the sequence of my operation is:
db.open
DE.commands(1).ComandText = "sql string"
DR.show
db.close
DE.conn.close
-run time err-
compactDatabase "usedDB","newDB",,dbLangGeneral
Why, the connection on the DB it is not completly close in the last instuction? I can see in the file system that the file dbName.ldb isn't close!
How To CLOSE An ADODC Connection
Hi all!
I'm sure this is a really foolish question, but I have searched the help and looked in several books and cannot find HOW to do this.
I have a form with an ADO Data Control and a DataGrid control - the DataGrid conrol DataSource is the ADODC and the ADODC gets connected to various tables in a few different databases depending upon the current context.
Is there a way to get the ADODC connection to COMPLETELY disconnect from the database? The databases are all MSAccess .mdb files and whenever the ADODC is connected there is the associated .ldb lock file present and I can't overwrite the file with any utilities.
I have tried ADODC1.Recordset.Close (which succeeds) but this does not remove the connection to the database.
Thanks for help with what is probably obvious if I only looked in the correct place.
How To Close Adodc-connection
I want to copy my database from place A to B, there is only one problem. since de database is connected I have to delete this connection.
How can I close that link?
When To Close The Connection And Recordset?
I have a form that opens a connection and a recordset (ADO). Initially I use the recordset to populate an MSFlexGrid. While the form is open, the user can click on a row to display all the info for the selected record in some text fields. The user can also add, delete, and update a record.
When should I close the connection and the recordset? Should it be when the form gets unloaded? Should it be after each operation (e.g. update)
Please advice
PS: I should mention that after I manage to get to the point that my form functions the way it should, I will add more forms in my application. These other forms will open other connections and recordsets
Help To Close The Connection With Database
Dear friend
I m creating asoftware in which i am trying to provide the restore database option it will restore the database to previous backup of the database . The problem is when i try to resotre the database it is working fine but when i use the database in one or two windows. It gives me an error permission is denied. though i close all windows and i m not using any class module still i do not understand why it happen. I think that probably connection with the database is not closed when i close the windows. Is there any solution to fix this problem.
Plz!!! help its urgent
Thanks in advance
shivpreet2k1
Can't Close Winsock Connection
Hi
For my code:
Private Sub cmdclose_Click()
winsock1.Close
DoEvents
End Sub
Private Sub winsock1_Close()
MsgBox "Closed"
End Sub
The msgbox never comes up. Is this because the winsock connection was never closed?
How To Close A Dial Up Connection
in my project i use the winsock control to connect to a certain ip.
when i do
wskWinsock.Connect strIP, intPort
then it automatically opens the windows dialog asking which dial up connection i want to use .. after i chose one .. it dials it .. and then it goes to the ip i want.
to close the winsock i do
wskWinsock.close
but this still leaves the connection open.
is there a way to close the connection from within my code ?
(i am using vb6 on win98se)
will this also close Rnaapp ?
when i close the connection by hand (right click in systray, click on disconnect) then Rnaapp still keeps running.
when i then connect to the ip and port again with the winsock it doesnt make a new connection.
but when i first close Rnaapp (via <ctrl> <alt> <del>) then everything works fine again.
can someone please help me ? this is the aspect of my project that doesnt work properly
Can't Close A DataEnv Connection
I must be missing something here but VB tells me I can't close the object in this context
(envconnection is a connection to a valid dataEnvironment)
Code:
With EnvConnection.rscomBonExtMain
.Open
Do While Not .EOF
If .Fields("BonExtID") = strBonExtID Then
.Fields("Bedrag") = .Fields("Bedrag") + (Val(txtAantal.Text) * Val(txtPrijs.Text))
.Close
Exit Do
Else
.MoveNext
End If
Loop
End With
What on earth am I doing wrong ? (probably something small as usual )
How To Close Adodc Connection?
hi..i have these lines to open the connection:
Dim cims As ADODB.Connection
Dim book_sales As ADODB.Recordset
Dim vcs As String
Set cims = New ADODB.Connection
Set book_sales = New ADODB.Recordset
vcs = "Provider=Microsoft.Jet.OLEDB.4.0;"
vcs = vcs & "Data Source=C:System"
vcs = vcs & "cims.mdb;Persist Security Info=False"
cims.Open vcs
book_sales.Open "book_sales", vcs, adOpenDynamic, adLockOptimistic, adCmdTable
how do i close it? thanks in advance.
Problem With Close Connection...
i have Frame1 with One DataGrid1 and Two Buttons
First Button connected to database and give data to DataGrid1
Code:
Public Com As ADODB.Connection
Public Rs As ADODB.Recordset
Set Com = New ADODB.Connection
Set Rs = New ADODB.Recordset
Dim sql As String
sql = "SELECT * FROM data.dbf WHERE NR_ROL LIKE " & NIRtxt.Text
Com.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=C:Data;"
Rs.Open sql, Com, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = Rs
Second button Command1 call "Exit"
and i wanna close connection when i exit this frame so i write
Code:Private Sub Command1_Click()
Rs.Close
Com.close
Set DataGrid1.DataSource = Rs
And now when i open frame1 and not connect to database then click Exit (Command1 button) i have Error "Object variable or with block wariable not set" because i not connected to dbf file how to make this when i not connect and click exit then don't give error?
Edited by - Speech on 8/28/2003 3:25:54 PM
How To Close A Socket Connection?
Hi Gurus,
I have a question on how vb's socket operation. The scenario is like:
Code:
' open connection
client = TcpClient(ip, port)
...
' close connection
client.close()
After connection set up, I can see an established connection using netstat besides the server's listening port.
Code:
TCP 0.0.0.0:9500 0.0.0.0:0 LISTENING
TCP 127.0.0.1:9500 127.0.0.1:1378 ESTABLISHED
"9500" is the server's listening port. My server is running on the same machine with my client.
I've thought after close(), the established connection should be removed. However, nothing changes.
Then, after I close the client app, the connection turns into,
Code:
TCP 127.0.0.1:1378 127.0.0.1:9500 TIME_WAIT
Hmm... I know little about what the status should be in response to vb's socket operation. Is this normal? Thank you.
How To Close The Connection Of Adodc
I created the adodc by placing the adodc(ADO data control) component to the form and use “use data link file” to open the connection. I need to close the connection to avoid the problem in Access log file. Anyone knows how? Thanks!
Alice
Close A ADODC Connection
Hi all,
Half an hour before I have made a question about CompactDatabase, the answer is Excelent, but now I have problems because I don't know how can I close the connection that make my DataControl (Adodc).
Thanks in advance
________________________________________________________________________
Miquel Gilabert mailto:se04249@salleurl.edu
Test & Software Engineering
Smart Cards & Terminals
Test & Transactions Europe
Technical Department - SLB Solaic Ibérica
Tel : (34) 93 462.83.00
Fax : (34) 93 462.83.27
Close A Inet Control Connection
Hi
I use the Inet control, to check if a page exist. Howevere, it seems that I don't close the connection. Because, after about 2000 request I manage to Dos(denial of service) my self. So I'm basicly using every port possible, until my ruter just shuts down.
my code is simply
inet.openurl (url)
Any idea?
- preben
Connection Close Causes Errorless Crash.
I'm not positive this is the right forum for this question, but the 'error' is caused by an Ado method, so:
I have a program which fills several things on a screen during its load function, including some text labels and an MSHFlexgrid. As it happens, These processes occur in two seperate functions, first there is 'populate labels', then 'populate flexgrid'.
In each case, an ado connection is made to a SQL (MSDE) server at the beginning of the function, and closed at the end of it. Now, there's no problem on my development machine. But on two other's I've tried, the flexgrid filling routine has a problem when I try to close the SQL connection.
When it reaches the line 'conSQL.close' it chokes -- there is no error, but the program stops running (no longer appears in task manager either). All the 'msgBox' lines I added in to try to find out where it was crashing.
Any ideas? Here is the 'pseudo-code' version, I can give exact code if needed. All of the "connection strings" are working though, they return the appropriate results if I show them on a modal form during this process.
Code:
'open SQL connection
conSQL.ConnectionString = gstrConn
conSQL.CursorLocation = adUseServer
conSQL.Open gstrConn
'Determine what gets selected
With frmQuickCom.mhfgMessage
.Redraw = False
Set .DataSource = conSQL.Execute(strFullQuery & strWhere & strOrder)
If glbooSel = True Then
.TopRow = glintRow
'.Enabled = True
Else
If .Rows > 1 Then
'.Enabled = True
.TopRow = 1
.Col = 0
.ColSel = 0
'Display first Message, security dependant
strSecurity = .TextMatrix(1, 10) 'security
If strSecurity = "Patient" Or strSecurity = "Staff" Then
'show subject
frmQuickCom.rtfMessage.Text = .TextMatrix(1, 8)
Else
'show message
frmQuickCom.rtfMessage.Text = .TextMatrix(1, 9)
End If
'Pick Max incoming ID
lngID = .TextMatrix(1, 0)
Else
'.Enabled = False
End If
End If
'set column size
.ColWidth(0) = 0 'ID
.ColWidth(1) = 0 'To Class
.ColWidth(2) = 0 'To_ID
.ColWidth(3) = 1000 'To_Name
.ColWidth(4) = 1200 'Time
.ColWidth(5) = 0 'To_Class
.ColWidth(6) = 0 'To_ID
.ColWidth(7) = 1000 'To_Name
.ColWidth(8) = .Width - .ColWidth(3) - .ColWidth(4) - .ColWidth(7) - (.GridLineWidth * (.Cols + 1)) 'Subject
.ColWidth(9) = 0 'Message
.ColWidth(10) = 0 'Security
'show it
.Redraw = True
End With
'Sound Start
Dim strSoundSet, strStationSound As String
Dim adoRecSound As New ADODB.Recordset
adoRecSound.Open "Connection String", conSQL, adOpenStatic, adLockOptimistic
'find sound folder
Dim strPath As String
strPath = App.Path & ("sound")
'now look through adorecsound
Do While Not adoRecSound.EOF
'for each message, add that users sound to sound collection
'SOUND CODE HERE
'move to the next user
adoRecSound.MoveNext
Loop
'repeat for Station Sound
Dim strSound As String
adoRecSound.Close
adoRecSound.Open "SELECT Sound FROM Practice", conSQL, adOpenStatic
If Not adoRecSound.EOF Then 'There exists a station sound to play
strSound = adoRecSound.Fields("Sound")
adoRecSound.Close
Dim lngSound2 As Long
Dim fsoStation As New FileSystemObject
'check if that is a valid sound file
If fsoStation.FileExists(strPath & strSound) = True And strSound <> "" Then
'now check for messages
adoRecSound.Open "Connection string", conSQL, adOpenStatic, adLockOptimistic
'messages exist?
If Not adoRecSound.EOF Then
'SOUND CODE HERE
End If
adoRecSound.Close
End If
Else
adoRecSound.Close
End If
'clean up
Set adoRecSound = Nothing
End If
'check for messages to everyone for flashing
Dim adoRecFlash As New ADODB.Recordset
adoRecFlash.Open "connection string", conSQL, adOpenStatic, adLockOptimistic
'pull ID and class, loop either staff or room array
Dim strClass As String
Dim i, intEnd, intID As Integer
Do While Not adoRecFlash.EOF
strClass = adoRecFlash.Fields("To_Class")
intID = adoRecFlash.Fields("ID")
'do some stuff here
adoRecFlash.MoveNext
Loop
MsgBox "Flash work ended", vbOKOnly, "Flash Work End"
'clean up
adoRecFlash.Close
MsgBox "adorecflash closed", vbOKOnly, "Closing adorecflash"
Set adoRecFlash = Nothing
'this msgbox gets shown:
MsgBox "adorecflash = nothing", vbOKOnly, "AdoRecFlash is Nothing"
conSQL.Close
'it doesn't make it here:
MsgBox "After Flash, Pre-pop-up", vbOKOnly, "A Flash, B pop-up"
Close DB Connection (Type Mismatch)
I am getting a type mismatch on the highlighted. Do I need to set both the connection and recordset even though they are Dimmed public?
VB Code:
Public Sub CloseConnection() 'Set m_ADORs = New ADODB.Recordset 'Set m_ADOCon = New ADODB.Connection If [hl]m_ADORs[/hl] = adStateOpen Then m_ADORs.Close End If Set m_ADORs = Nothing If m_ADOCon = adStateOpen Then m_ADOCon.Close End If Set m_ADOCon = NothingEnd Sub
Unable To Perform Db Connection Close
I use a public DB Connection.
Code: Public CN As New ADODB.Connection
Public Sub DBConnect() ' Global Connection Command
Set CN = New ADODB.Connection
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "PATTEST.mdb;Persist Security Info=False"
End Sub
I call it by using:
Code:Public Sub Loadcustomers()
Dim custnm As New ADODB.Recordset
Set custnm = New ADODB.Recordset
Call DBConnect
custnm.Open "Select CompanyName from customers", CN
While Not custnm.EOF
custinfo.cbocompname.AddItem custnm.Fields("CompanyName")
custnm.MoveNext
Wend
custnm.Close
End Sub
and close the project using:
Code: Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
Call DBConnect
'If CN.State = adStateOpen Then CN.Close
Set CN = Nothing
CN.Close
End Sub
However the PATTEST.ldb is still there.
Thanks in advance
Failed To Close Socket Connection
hi,
i am using a Winsock control in my application.
i wrote some lines of code in the Close event of the control but when i activate the Close function it doesn't close the connection and dont get into the Close event.
is that a common problem? any idea how to solve it?
thank,
ohad.
|