Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Close FTP Connection Using Inet

this is how im connecting..

With Inet1
.Protocol = icFTP
.URL = ""
.UserName = "username"
.Password = "password"
End With

but i just realized that im not closing this connection... would i use the .cancel?


or do i even need to close it?

also why am i using the . Cancel here?

With Inet1


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Close A Inet Control Connection

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

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"
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.

Difference Between Connection.close And Set Connection=nothing
we are using set connection=nothing,but we are not closing the connection.will it cause any problem if more number of connections are there.

Connection Begintrans Cannot Close The Connection

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.


adodcTrxHdr("TRX_DATE") = dtpTrxDate.Value
adodcTrxHdr("TRX_CODE") = txtTrxNo.Text
adodcTrxHdr("CUST_CODE") = txtCustomerCode.Text

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


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...

Inet Connection
How do I get my internet dialup connection to be activated automatically?...I am looking into the modem dialup commands with hopes of finding something there that I can use...Any help is appreciated

Vb->DB Connection Or Inet POST?
Through VB, i want to add infromation to a database I have on the internet. I know it's possible to connect to a remote mySQL db and all, but would it be wise or stupid to just use the Inet or winsock control to POST data to a PHP script that performs the mySQL commands (all posted data would be encrypted). POST'ing the data is probably not as reliable, but for this application it does not need to be (data may be sent every few minutes).

any suggestions are appreciated.

Inet Cancel Connection
Hi all,
I writing an FTP apllication for my networking course major project (Something like CuteFTP or LeapFTP).
Well, it's all fine, but i am having problems with 2 issues:

1) When connecting, i want to be able to abort the operation. I mean user can be able to stop any connection attempt currently going on. I tried using Inet.Cancel method (The only method that deals with cancelling requests in the inet control), but this only works when executing a command after being connected, like put, get, ... When trying to cancel when trying to connect, it returns an error (Still executing last request). How to cancel a connection attempt??

2) How can i retrieve the IP of the Server Host being connected to? I mean i want to display a message like Host Resolved as, or something like that. Can this be done using the inet control (the StateChanged event??) or should i do this separetly?? And how??

Please help me people, cause this project is due in a couple of days, and i'm ruuning out of ideas.
Thanx in advance

Checking Inet Connection??
How can I tell if an Inet connection exists WITHOUT using the Public Declare Function InternetGetConnectedState Lib "wininet" API.

Halt Inet Connection

I have a program that searches for given file and tries to download it. Under my "Cancel" button I have this code:

Unload Me

When I use that code, the program still runs in the background. How do I REALLY cancel the inet process?

Inet Connection Problem
I am trying to use the inet control.
It doesn't seem to be able to connect with the server.
I connect to the server frequently using telnet so I am sure its not a server problem.
The code I am trying to use is:

Inet1.Protocol = icFTP
Inet1.UserName = MyUserNmae
Inet1.Password = MyPassWord
Inet1.Execute "","Dir *.*" is what I type in the telnet hostname text box,I hope its the right parameter to give to the execute method.
Although msdn clame that I have to put in a protocol type in the url name.
How do I do that for ftp?

How can I display all directories of my account on the remote ,server in a listbox in my app?
(the remote system is unix)


Reset Inet After Connection Error?
I made a program that downloads a file with Inet and programmed it to do 3 retry attempts if any error occurs.

If the problem is the server thats not responding, it successfully works at the next attempt, but if I unplug my network cable, then plug it back in, at the next attempt it stillcant connect and I muct stop and restart the project for it to work.

Is there a way to reset or unload/reload the Inet control (unless theres another/better way) to make it work with the new connection?


Inet Freezing If Connection Lost
Hi there

I am using the inet control to automatically download updates for my application. It works fine, but the problem is that if the internet connection is lost, then it just freezes. Is there some event in Inet that I could use to check for this?

Many thanks


Detecting Preffered Inet Connection And Using It?
Hi All,

I am writing a program that uploads some files to the specified FTP server. This is nearly finished and uploads the files correctly etc provided the user is connected to the internet. (I have used API calls to the Wininet.dll).

What I need to do know is how do I find out what the users default internet connection is, and open it?


If they have multiple dial up connections, dial the default, or offer them a choice of connections.

If they connection via a gateway off their network, check if this is a vailable etc.

Any help would be greatly appreciated... Thanks.

Trouble With Inet.openurl After Failed Connection

I'm writing a little application which uses inet.openURL to bring back a variable from a number of remote systems.

I've come across a strange issue where if it fails on connection to one of the systems, for the next system it attempts it doesn't seem to do anything at all?

Here is some example code (I've also uploaded the demo app) where I have 5 different sites to connect to, sites 3 and 4 do not exist.

If you click on site1, it will bring back a result ok.
If you click on site3, it will bring back an error ok.
Now that we've had a failed connection, try clicking either a good or bad site - it does nothing?? It seems to take 2 attempts before it gets the next good or bad result.

I would really appreciate any help, I've been looking at this for a couple of days and can't see any reason why it's acting in this way.

Private Sub Form_Load()
Inet1.RequestTimeout = 7
End Sub

Private Sub cmd_check1_Click()
On Error GoTo Check1Error:
txt_result1.Text = Inet1.OpenURL(txt_string1.Text)
Exit Sub

txt_result1.Text = Err.Description
End Sub

Private Sub cmd_check2_Click()
On Error GoTo Check2Error:
txt_result2.Text = Inet1.OpenURL(txt_string2.Text)
Exit Sub

txt_result2.Text = Err.Description
End Sub

Private Sub cmd_check3_Click()
On Error GoTo Check3Error:
txt_result3.Text = Inet1.OpenURL(txt_string3.Text)
Exit Sub

txt_result3.Text = Err.Description
End Sub

Private Sub cmd_check4_Click()
On Error GoTo Check4Error:
txt_result4.Text = Inet1.OpenURL(txt_string4.Text)
Exit Sub

txt_result4.Text = Err.Description
End Sub

Private Sub cmd_check5_Click()
On Error GoTo Check5Error:
txt_result5.Text = Inet1.OpenURL(txt_string5.Text)
Exit Sub

txt_result5.Text = Err.Description
End Sub

Inet Control Does Not Raise Modem Connection Dialog
I minor irritation to the project that I am currently developing, is that Inet works perfectly on my machine; attempting to use it without an established net conenction causes the "please select a conenction to dial" window to appear, int he same way that IE does

For my co-worker, also an XP user, the window appears, though his modem is faluty, so no dialling takes place.

On the third system, and the actual target for the product, it doesnt bother displaying the window at all, regardless of whether there is a disconnected or connected modem connection, or lan connection. under no configuration, will Inet bother accessing the internet. Does anyone have any suggestions of things to try, even debugging suggestions, or what i can look at to trace the behaviour? the target system has no development environment at all. Perhaps replacing Inet with a better component would be an aswer, as throughout the entire edvelopment process, i've found Inet to be a somewhat lacklustre component. Does anyone have suggestions for a better one (apart from writing my own with winsock.. which i'd rather not do, but dont mind if i have to)


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

Dim strCn as String
strCn = ConnectString()

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!



Close Connection
how do i disconnect or end connection to the internet at a set time?


Close Connection
Hi Everyone,

I am using this form to run a sql statement.


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.

Close Connection
how do u close connection of data report?

How To Close The Connection
Hi there

I have this piece of code



Dim Conn As New ADODB.Connection

On Error GoTo Errorhandler

Conn.ConnectionString = strdsn
'...some insert etc statements here
conn.execute query

strErr = strErr + Err.Description
If Conn.State = 0 Then

End If

If Conn.State = 1 Then
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?

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?!?!?!

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.

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:

DE.commands(1).ComandText = "sql string"


-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!

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)

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

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


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


Can't Close Winsock Connection

For my code:

Private Sub cmdclose_Click()
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

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)

With EnvConnection.rscomBonExtMain
Do While Not .EOF
If .Fields("BonExtID") = strBonExtID Then
.Fields("Bedrag") = .Fields("Bedrag") + (Val(txtAantal.Text) * Val(txtPrijs.Text))
Exit Do
End If
End With

What on earth am I doing wrong ? (probably something small as usual )

How Do I Close An Internet Connection?
Could one of you great VB coders please tell me how I can close an internet connection.

Many thanks,

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.

How Often Should I Open/close A Connection To A DB

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

Problem With Close Connection...
i have Frame1 with One DataGrid1 and Two Buttons

First Button connected to database and give data to DataGrid1

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;" & _
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()
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:


' open connection
client = TcpClient(ip, port)
' close connection

After connection set up, I can see an established connection using netstat besides the server's listening port.



"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,



Hmm... I know little about what the status should be in response to vb's socket operation. Is this normal? Thank you.

When To Open/close A Connection
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

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!


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
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

HowdoI Make My Vb6 Program Dial A Connection On Command (if No Inet Present)?
I have a reporting application that uses a modem.
The modem is suppose to stay connected 100percent of the time.. but like right now, the connection was lost becasue of the weather.
I setup winXP to redial up to 1000times with1second wait times... but the weather lasted longer than 1000seconds.

So, basically, how can I make my program dial a certain connection when it is told too (given the connection is down)?

And when I say dial.. all the information (number/username/pw) is stored in the connection.. so basically all I had to do was initiate was put a shortcut to the connection in my startup menu..

any ideas?


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?

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.

'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
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)
'show message
frmQuickCom.rtfMessage.Text = .TextMatrix(1, 9)
End If
'Pick Max incoming ID
lngID = .TextMatrix(1, 0)
'.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


'move to the next user

'repeat for Station Sound
Dim strSound As String
adoRecSound.Open "SELECT Sound FROM Practice", conSQL, adOpenStatic

If Not adoRecSound.EOF Then 'There exists a station sound to play
strSound = adoRecSound.Fields("Sound")
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
End If
End If
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


MsgBox "Flash work ended", vbOKOnly, "Flash Work End"

'clean up

MsgBox "adorecflash closed", vbOKOnly, "Closing adorecflash"
Set adoRecFlash = Nothing

'this msgbox gets shown:
MsgBox "adorecflash = nothing", vbOKOnly, "AdoRecFlash is Nothing"


'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

Copyright © 2005-08, All rights reserved