LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Avi Avi is offline
external usenet poster
 
Posts: 29
Default issue with ODBC connection to DB2

Thanks for the reply Jim !

strQueryText is defined as String and I am getting it from the
Spreadsheet cell.

query i am trying to execute is simple - "Select Item from XYZ.ITEM
where dept = 200 "

Here is the complete procedure.
-----------------------------------------------------------------------------
Private Sub CreateQuery(inQueryIdx As Integer)
'
Dim strQueryName As String, strQueryText As String
Dim strServer, strDatabase, strUid, strPwd As String
Dim xSheet As Worksheet

strQueryName = [querylist].Cells(inQueryIdx, 1)
strQueryText = [querylist].Cells(inQueryIdx, 2)

If strQueryName = "" Or strQueryText = "" Then
Exit Sub
End If

strServer = [querylist].Cells(inQueryIdx, 3)
strDatabase = [querylist].Cells(inQueryIdx, 4)
strUid = [querylist].Cells(inQueryIdx, 5)
strPwd = [querylist].Cells(inQueryIdx, 6)

FindActivateSheet (strQueryName)
Cells.Select
Selection.Delete Shift:=xlUp
Range("A1").Select

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;Driver={IBM DB2 ODBC
DRIVER};Hostname=udb_db2t.xxx.com;Port=2001;DB=DB2 T;Uid=xxx;Pwd=xxx;"
_
, Destination:=Range("A1"))
.CommandText = strQueryText
.Name = strQueryName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.EnableRefresh = True
.EnableEditing = False
.Refresh BackgroundQuery:=False
End With

Set xSheet = ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
'xSheet.Columns(9).WrapText = True
Set xSheet = Nothing

End Sub
-----------------------------------------------------------------



On Aug 2, 11:36 am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
What is the value of strQueryText
in the line
.CommandText = strQueryText
--
HTH...

Jim Thomlinson

"Avi" wrote:
Hi,


I am connecting to DB2 from Excel using IBM OBDC driver. I am able to
connect and getting the data but.. there is a window that pops up
asking me to select the database.. is there a way to get rid of it


here is my code.
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;Driver={IBM DB2 ODBC
DRIVER};Hostname=udb_db2t.xxxxx;Port=2001;DB=DB2T; Uid=xxx;Pwd=xxxxx;"
_
, Destination:=Range("A1"))
.CommandText = strQueryText
.Name = strQueryName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.EnableRefresh = True
.EnableEditing = False
.Refresh BackgroundQuery:=False --- this row pops the
window...
End With


I also see the error message in the window "SQL1013N The database
alias name or database name "" could not be found. SQLSTATE=42705"


looks like i am not defining the database properly..


Can someone please help ..


Thanks
Avinash



 
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
ODBC connection failed. Jim Moberg Excel Discussion (Misc queries) 0 October 9th 06 03:48 PM
ODBC Connection Kezzemil Excel Programming 0 October 6th 06 09:15 AM
ODBC connection question matelot Excel Programming 1 September 23rd 06 08:46 PM
ODBC Connection Adrian T[_4_] Excel Programming 4 January 25th 05 08:55 PM
ODBC connection by udl Dorothy[_4_] Excel Programming 1 January 8th 04 05:32 PM


All times are GMT +1. The time now is 08:05 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"