Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Oracle database login

I have the following code running a stored procedure against an Oracle
database; however, I want to force a user login with a password. I found if
I blank out the user id and password, the macro fails and does not prompt for
the userid and password. How can I modify this to get the macro to prompt
for these items?

Thanks!

Sub Button41_Click()
'
' Button41_Click Macro
' Macro recorded 11/24/2003
'

'Sample Database connection to an Oracle Database with 2 Input Parameters
and 1 Output Parameter, taking
'the parameters from cells in the Excel Worksheet
Dim dbConnection As New ADODB.Connection
Dim dbRecordset As New ADODB.Recordset
Dim myCurCell As Range
Dim myCurCell2 As Range
Dim myCurCell3 As Range
Dim oWorkSheet As Worksheet
Dim dbCommand As New ADODB.Command
Dim dbParameter As New ADODB.Parameter
Dim dbParameters As New ADODB.Parameter
Dim strMessage As String

On Error GoTo ErrorHandler

'Set the worksheet to pull the values from
Set oWorkSheet = ThisWorkbook.Worksheets(1)

'********Modify this range if the parameter values are actually located in
the spreadsheet itself***********
With oWorkSheet
'Grab the values from the selected cells and populate
Set myCurCell1 = .Range("C2")
Set myCurCell2 = .Range("C3")
Set myCurCell3 = .Range("C4")
Set myCurCell4 = .Range("C5")
End With

'Set the connection and open
'***************Make changes to the connection string*****************
dbConnection.Provider = "msdaora"
dbConnection.Open ("Data Source=xxxxxx;Password=xxxx;User ID=xxxxxx")


'Set the command object and the parameters
dbCommand.ActiveConnection = dbConnection

'Set the command type and name / parameters if applicable
dbCommand.CommandType = adCmdStoredProc

'***********Set the stored procedure name*****************
dbCommand.CommandText = "sp_run_sp" 'Stored Procedure Name

'Create / Append the parameters
'*********If there are no parameters you can delete the lines up to the
Execute() code************
Set dbParameter = dbCommand.CreateParameter("iCompany", adVarChar,
adParamInput, 30, myCurCell1)
dbCommand.Parameters.Append dbParameter

Set dbParameter = dbCommand.CreateParameter("ialloc_tport", adVarChar,
adParamInput, 30, myCurCell3)
dbCommand.Parameters.Append dbParameter

Set dbParameter = dbCommand.CreateParameter("iAcctDate", adDate,
adParamInput, 30, myCurCell4)
dbCommand.Parameters.Append dbParameter

Set dbRecordset = dbCommand.Execute()


'strMessage = dbCommand.Parameters(2).Value
'strMessage = dbCommand.Parameters(2).Value

'Close the Connection
dbConnection.Close

'
' Macro3 Macro
' Macro recorded 11/4/2004
'

'
Range("D5").Select
Sheets("Data").Select
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Unit Costs").Select
Range("A4").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Pivot").Select
Range("D5").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh
Sheets("Run SALESMARGIN").Select
Range("D4").Select

Exit Sub
ErrorHandler:
dbConnection.Close
Err.Raise Err.Number, Err.Source, Err.Description


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Oracle database login

This is one of those rare occasions when a global variable makes a lot of
sense. When I have implimented similar code I have used a login procedure at
the beginning of the program and then any time I need to login I grab the
user name and password that were populated when the program began. This
allows me to login and log back out as often as is needed without having to
constantlly ask the user. Just my two cents...
--
HTH...

Jim Thomlinson


"Tim Reid" wrote:

I have the following code running a stored procedure against an Oracle
database; however, I want to force a user login with a password. I found if
I blank out the user id and password, the macro fails and does not prompt for
the userid and password. How can I modify this to get the macro to prompt
for these items?

Thanks!

Sub Button41_Click()
'
' Button41_Click Macro
' Macro recorded 11/24/2003
'

'Sample Database connection to an Oracle Database with 2 Input Parameters
and 1 Output Parameter, taking
'the parameters from cells in the Excel Worksheet
Dim dbConnection As New ADODB.Connection
Dim dbRecordset As New ADODB.Recordset
Dim myCurCell As Range
Dim myCurCell2 As Range
Dim myCurCell3 As Range
Dim oWorkSheet As Worksheet
Dim dbCommand As New ADODB.Command
Dim dbParameter As New ADODB.Parameter
Dim dbParameters As New ADODB.Parameter
Dim strMessage As String

On Error GoTo ErrorHandler

'Set the worksheet to pull the values from
Set oWorkSheet = ThisWorkbook.Worksheets(1)

'********Modify this range if the parameter values are actually located in
the spreadsheet itself***********
With oWorkSheet
'Grab the values from the selected cells and populate
Set myCurCell1 = .Range("C2")
Set myCurCell2 = .Range("C3")
Set myCurCell3 = .Range("C4")
Set myCurCell4 = .Range("C5")
End With

'Set the connection and open
'***************Make changes to the connection string*****************
dbConnection.Provider = "msdaora"
dbConnection.Open ("Data Source=xxxxxx;Password=xxxx;User ID=xxxxxx")


'Set the command object and the parameters
dbCommand.ActiveConnection = dbConnection

'Set the command type and name / parameters if applicable
dbCommand.CommandType = adCmdStoredProc

'***********Set the stored procedure name*****************
dbCommand.CommandText = "sp_run_sp" 'Stored Procedure Name

'Create / Append the parameters
'*********If there are no parameters you can delete the lines up to the
Execute() code************
Set dbParameter = dbCommand.CreateParameter("iCompany", adVarChar,
adParamInput, 30, myCurCell1)
dbCommand.Parameters.Append dbParameter

Set dbParameter = dbCommand.CreateParameter("ialloc_tport", adVarChar,
adParamInput, 30, myCurCell3)
dbCommand.Parameters.Append dbParameter

Set dbParameter = dbCommand.CreateParameter("iAcctDate", adDate,
adParamInput, 30, myCurCell4)
dbCommand.Parameters.Append dbParameter

Set dbRecordset = dbCommand.Execute()


'strMessage = dbCommand.Parameters(2).Value
'strMessage = dbCommand.Parameters(2).Value

'Close the Connection
dbConnection.Close

'
' Macro3 Macro
' Macro recorded 11/4/2004
'

'
Range("D5").Select
Sheets("Data").Select
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Unit Costs").Select
Range("A4").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Pivot").Select
Range("D5").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh
Sheets("Run SALESMARGIN").Select
Range("D4").Select

Exit Sub
ErrorHandler:
dbConnection.Close
Err.Raise Err.Number, Err.Source, Err.Description


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
Downloaded from Oracle Database Sarah at DaVita Excel Discussion (Misc queries) 0 January 30th 07 06:11 PM
How to get data from Oracle Database to Excel? David Willis New Users to Excel 1 March 31st 06 01:57 PM
ODBC/VBA?EXCEL and ORACLE database BAC Excel Programming 7 July 14th 05 12:55 PM
Connect to Oracle Database through ODBC with VBA jamiee Excel Programming 1 April 15th 04 03:31 PM
SQL.Request from Oracle Database CraigRhino Excel Programming 1 February 25th 04 10:33 PM


All times are GMT +1. The time now is 02:01 AM.

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"