Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
b_r b_r is offline
external usenet poster
 
Posts: 2
Default Excel - Oracle database connection

Hi,

I have some problems!

- when I open the workbook I make oracle database connection:

Public Sub Workbook_Open()
Dim conOracle As ADODB.Connection
Set conOracle = New ADODB.Connection

conOracle.Open "DSN=db1; User ID=user; prompt = complete"
End Sub

- then in a normal module i run some macro and want to check if
connection is active

Sub Check_connection()
Dim conOracle As ADODB.Connection

check_con = conOracle.State
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Excel - Oracle database connection

When your workbook open code ends so does conOracle... You could make
conOracle into a global varaible at which point it will persist after the
procedure ends. That being said I normally avoid holding connections to
databases for the duration of the application. It is possibly not an
efficient use of your system resources. I would be inclined to remove the
workbook open code and then connect and disconnect as is necessary. Something
like this

Sub Check_connection()
Dim conOracle As ADODB.Connection
Set conOracle = New ADODB.Connection

conOracle.Open "DSN=db1; User ID=user; prompt = complete"
check_con = conOracle.State
  #3   Report Post  
Posted to microsoft.public.excel.programming
b_r b_r is offline
external usenet poster
 
Posts: 2
Default Excel - Oracle database connection

Thank you Jim.

I use solution what you proposed but at every database interrogation I
have to log in what is inconveniet when I login several times during 2-4
minutes and that is the reason why I wanted to open connection once.

Maybe it is better way to make this action in one module using "if"
connection active or not.

Best Regards
BR

Jim Thomlinson napisał(a):
When your workbook open code ends so does conOracle... You could make
conOracle into a global varaible at which point it will persist after the
procedure ends. That being said I normally avoid holding connections to
databases for the duration of the application. It is possibly not an
efficient use of your system resources. I would be inclined to remove the
workbook open code and then connect and disconnect as is necessary. Something
like this

Sub Check_connection()
Dim conOracle As ADODB.Connection
Set conOracle = New ADODB.Connection

conOracle.Open "DSN=db1; User ID=user; prompt = complete"
check_con = conOracle.State
.
.
conOracle.close
set conoracle = nothing
end sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Excel - Oracle database connection

What you are proposing is to use a global variable which is a viable route to
go. Use your on open code but instead of declaring the variable in the
procedure declare it public at the top of as standard module. My only comment
would be where you know you are going to have a long period of inactivity
close the connection. You can then use your ".state" to check if the
connection is active.
--
HTH...

Jim Thomlinson


"b_r" wrote:

Thank you Jim.

I use solution what you proposed but at every database interrogation I
have to log in what is inconveniet when I login several times during 2-4
minutes and that is the reason why I wanted to open connection once.

Maybe it is better way to make this action in one module using "if"
connection active or not.

Best Regards
BR

Jim Thomlinson napisał(a):
When your workbook open code ends so does conOracle... You could make
conOracle into a global varaible at which point it will persist after the
procedure ends. That being said I normally avoid holding connections to
databases for the duration of the application. It is possibly not an
efficient use of your system resources. I would be inclined to remove the
workbook open code and then connect and disconnect as is necessary. Something
like this

Sub Check_connection()
Dim conOracle As ADODB.Connection
Set conOracle = New ADODB.Connection

conOracle.Open "DSN=db1; User ID=user; prompt = complete"
check_con = conOracle.State
.
.
conOracle.close
set conoracle = nothing
end sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link ODBC connection to an Oracle database Richard Excel Discussion (Misc queries) 1 November 5th 06 04:29 PM
Changing Oracle connection from DSN to DSN-Less Red[_4_] Excel Programming 3 October 7th 05 10:42 AM
ADO Connection to ORACLE 9.2 through EXCEL fails Dave Bash Excel Programming 5 November 14th 04 06:32 AM
connection to oracle with excel andy[_6_] Excel Programming 1 August 10th 04 03:53 PM
returning a spreadsheet from code - ASP, OO4O Oracle Database connection starbucknfinity Excel Programming 0 May 7th 04 03:16 PM


All times are GMT +1. The time now is 11:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"