PC Review


Reply
Thread Tools Rate Thread

Database Query

 
 
Vijay Kotian
Guest
Posts: n/a
 
      11th Jul 2008
I am extracting data from database by query table macro, while running macro
it connects database and it requires password to be entered every time. Is
it possible to enter password through macro, if yes, then how password can be
passed through macro?

Thank you in advance
 
Reply With Quote
 
 
 
 
vqthomf
Guest
Posts: n/a
 
      11th Jul 2008
Hi I Connect to my database like this cnn.Open
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & GetFromIniFile("dBPath",
"MaindB", PurMLINI) & ";Jet OLEDBatabase Password=??????;"

"Vijay Kotian" wrote:

> I am extracting data from database by query table macro, while running macro
> it connects database and it requires password to be entered every time. Is
> it possible to enter password through macro, if yes, then how password can be
> passed through macro?
>
> Thank you in advance

 
Reply With Quote
 
Vijay Kotian
Guest
Posts: n/a
 
      11th Jul 2008
The following is my code, can you suggest where I should enter Password in
this code.

Thank you

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=10.9.21.753;UID=yajivk;;APP=Microsoft
Office 2003;WSID=PSIEPK000073" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT hotel_edart.REF_NO, hotel_edart.DEALER_ID,
hotel_edart.edart_DT, hotel_edart.EXCHANGE, hotel_edart.SEG_TYPE,
hotel_edart.CLIENT_CD, hotel_edart.SCRIP_CD, hotel_edart.TRANS_TYPE,
hotel_edart.QTY" _
, _
", hotel_edart.PRICE, hotel_edart.CREATED_DT,
hotel_edart.MODIFIED_DT, hotel_edart.AUTH_DT, hotel_edart.AUCTION_QTY,
hotel_edart.AUCTION_RATE, hotel_edart.SCRIP_NAME" & Chr(13) & "" & Chr(10) &
"FROM ET.dbo.hotel_edart hotel_TRAD" _
, _
"E" & Chr(13) & "" & Chr(10) & "WHERE (hotel_edart.edart_DT>{ts '" &
tmonth1 & " 00:00:00'}) AND (hotel_edart.SEG_TYPE='C')" & Chr(13) & "" &
Chr(10) & "ORDER BY hotel_edart.EXCHANGE, hotel_edart.SCRIP_NAME" _
)
.Name = "Query from 10.9.21"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

"vqthomf" wrote:

> Hi I Connect to my database like this cnn.Open
> "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & GetFromIniFile("dBPath",
> "MaindB", PurMLINI) & ";Jet OLEDBatabase Password=??????;"
>
> "Vijay Kotian" wrote:
>
> > I am extracting data from database by query table macro, while running macro
> > it connects database and it requires password to be entered every time. Is
> > it possible to enter password through macro, if yes, then how password can be
> > passed through macro?
> >
> > Thank you in advance

 
Reply With Quote
 
vqthomf
Guest
Posts: n/a
 
      11th Jul 2008
Sorry Vijay I have never connected to an SQL server I only connect to a
MSAccess dB I understand that the password comes at the end of the connection
string.
Regards

"Vijay Kotian" wrote:

> The following is my code, can you suggest where I should enter Password in
> this code.
>
> Thank you
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "ODBC;DRIVER=SQL Server;SERVER=10.9.21.753;UID=yajivk;;APP=Microsoft
> Office 2003;WSID=PSIEPK000073" _
> , Destination:=Range("A1"))
> .CommandText = Array( _
> "SELECT hotel_edart.REF_NO, hotel_edart.DEALER_ID,
> hotel_edart.edart_DT, hotel_edart.EXCHANGE, hotel_edart.SEG_TYPE,
> hotel_edart.CLIENT_CD, hotel_edart.SCRIP_CD, hotel_edart.TRANS_TYPE,
> hotel_edart.QTY" _
> , _
> ", hotel_edart.PRICE, hotel_edart.CREATED_DT,
> hotel_edart.MODIFIED_DT, hotel_edart.AUTH_DT, hotel_edart.AUCTION_QTY,
> hotel_edart.AUCTION_RATE, hotel_edart.SCRIP_NAME" & Chr(13) & "" & Chr(10) &
> "FROM ET.dbo.hotel_edart hotel_TRAD" _
> , _
> "E" & Chr(13) & "" & Chr(10) & "WHERE (hotel_edart.edart_DT>{ts '" &
> tmonth1 & " 00:00:00'}) AND (hotel_edart.SEG_TYPE='C')" & Chr(13) & "" &
> Chr(10) & "ORDER BY hotel_edart.EXCHANGE, hotel_edart.SCRIP_NAME" _
> )
> .Name = "Query from 10.9.21"
> .FieldNames = True
> .RowNumbers = False
> .FillAdjacentFormulas = False
> .PreserveFormatting = True
> .RefreshOnFileOpen = False
> .BackgroundQuery = True
> .RefreshStyle = xlInsertDeleteCells
> .SavePassword = False
> .SaveData = True
> .AdjustColumnWidth = True
> .RefreshPeriod = 0
> .PreserveColumnInfo = True
> .Refresh BackgroundQuery:=False
> End With
>
> "vqthomf" wrote:
>
> > Hi I Connect to my database like this cnn.Open
> > "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & GetFromIniFile("dBPath",
> > "MaindB", PurMLINI) & ";Jet OLEDBatabase Password=??????;"
> >
> > "Vijay Kotian" wrote:
> >
> > > I am extracting data from database by query table macro, while running macro
> > > it connects database and it requires password to be entered every time. Is
> > > it possible to enter password through macro, if yes, then how password can be
> > > passed through macro?
> > >
> > > Thank you in advance

 
Reply With Quote
 
Ed Ferrero
Guest
Posts: n/a
 
      11th Jul 2008
Hi Vijay,

> The following is my code, can you suggest where I should enter Password
> in
> this code.
>
> Thank you
>
> With ActiveSheet.QueryTables.Add(Connection:= _
> "ODBC;DRIVER=SQL
> Server;SERVER=10.9.21.753;UID=yajivk;;APP=Microsoft
> Office 2003;WSID=PSIEPK000073" _
> , Destination:=Range("A1"))
> .CommandText = Array( _


Add the password 'mypw' like this...

With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=10.9.21.753;UID=yajivk;PWD=mypw;APP=Microsoft
Office 2003;WSID=PSIEPK000073" _
, Destination:=Range("A1"))

Be careful how you deploy this, the password is stored in code, and Excel
VBA code is not secure.
I would at least password protect the code, but remember that it is easy to
crack protectedVBA code.
Should be ok if the Excel workbook is kept on a secure folder.

Ed Ferrero
www.edferrero.com

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
database query not showing foxpro database How I import data =?Utf-8?B?bWFuZ2F0?= Microsoft Excel New Users 1 24th Jun 2007 03:31 PM
Excel query of Access database - changed database filename, now error ucdcrush@gmail.com Microsoft Excel Discussion 2 8th Mar 2006 08:42 PM
HOWTO: display database without refresh web page to query database =?Utf-8?B?U1M=?= Microsoft ASP .NET 3 15th May 2005 09:22 PM
After restoring a database, SqlCommand still sees original database, MS Query Analyser shows restored data Tony Riv Microsoft ADO .NET 0 6th Apr 2005 09:18 AM
How to Add an All Values Item to a Database Query by Using the FrontPage 2003 Database Results Wizard =?Utf-8?B?RGFuaWVs?= Microsoft Frontpage 4 2nd Feb 2004 05:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 AM.