AutoHotkey Community

It is currently May 27th, 2012, 5:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 132 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9  Next
Author Message
 Post subject:
PostPosted: March 3rd, 2010, 4:51 pm 
Offline

Joined: December 13th, 2007, 11:41 pm
Posts: 31
I tried that twice, once within my program, and once just by itself, and got the same error (apparently I only got the other error once):

---------------------------
COM Error Notification
---------------------------
Function Name: "Open"
ERROR: (0x800A0E7F)
PROG:
DESC:
HELP: ,0

Will Continue?
---------------------------
Yes No
---------------------------

I'm going to try a few things, and I'll post if I have any success. Thanks, Sean.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 7:42 pm 
Offline

Joined: December 13th, 2007, 11:41 pm
Posts: 31
I installed a Office 2000 on this machine (with Access) to see if it would solve any missing or corrupt file issues, and no luck

I also tried to run SFC, but not having the original physical 2000 disk on this dinosaur machine makes that difficult. I did manage to change the registry to look at a copy of the i386 folder from another machine, but no luck there either.

I'm going to let this fall back off my to-do list. I love a mystery, but not one without clues.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2010, 1:17 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
My only suggestion remained is to try to re-install and/or update to the latest MDAC.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 23rd, 2010, 1:27 pm 
Offline

Joined: November 19th, 2009, 6:23 pm
Posts: 163
Location: Florida
HugeHugh wrote:
I have adapted namebran's solution to allow for getting the recordcount from the stored procedure result. You need to set the Cursorlocation to 3. This is working great:


Code:

#Include Lib\CoHelper.ahk
#Include Lib\Com.ahk

Com_CoInitialize()

idParam := "25"

sQuery := "MyStoredProcedureName"
sConnect := "Driver={SQL Server}; Server=servername; Database=dbname; UID=username; PWD=mypassword"
objcon := Com_ActiveXObject("ADODB.Connection")
objcmd := Com_ActiveXObject("ADODB.Command")

Com_Invoke(objcon, "CursorLocation", 3)   ; allows you to get RecordCount

Com_Invoke(objcon, "Open", sConnect)  ;Open
Com_Invoke(objcmd, "ActiveConnection", "+" . objcon)
Com_Invoke(objcmd, "CommandText", sQuery)
Com_Invoke(objcmd, "CommandType", 4)
Com_Invoke(objcmd, "NamedParameters", "True")

qParam1 := Com_Invoke(objcmd, "CreateParameter", "@idParam", 72, 1, 36, idParam)
objparam := Com_Invoke(objcmd, "Parameters")
Com_Invoke(objparam, "Append", "+" . qParam1)

spExec := Com_Invoke(objcmd, "Execute")
nRecordCount := Invoke(spExec, "RecordCount")

Loop, % nRecordCount
{
   pFields     := Invoke(spExec, "Fields")   ; Fields
   nFieldCount := Invoke(pFields, "Count")   ; Count
   sData       := ""

      Loop, %nFieldCount%
      {
          pField%A_Index% := Invoke_(pFields, "Item", 3, arg:=A_Index-1)      ; Item   
          sName  := Invoke(pField%A_Index%, "Name")   ; Name
          sValue := Invoke(pField%A_Index%, "Value")   ; Value
          sData .= sName . ":  " . sValue . "`r`n"
          Invoke(pField%A_Index%, "Release")           ; Release
      }

   MsgBox % sData

   Release(pFields)          ; Release
   Invoke(spExec, "MoveNext")  ; MoveNext
}


Com_Release(objcmd)
Com_Invoke(objcon, "Close")
Com_Release(objcon)
Com_CoUninitialize()
ExitApp



This code (and thread) helped me out... I slightly modified it though, mine uses LDAP syntax and I'm not getting a record count just grabbing certain fields that I need by name... there are some other slight differences too... but here's mine :) and it works...

Code:

COM_init()
COM_CoInitialize()

lastName = Doe
firstName = Jane

connProv := "ADsDSOObject"
connOpen := "Active Directory Provider"
Query := "<LDAP://myldapserver>;(&(objectclass=user)(objectcategory=person)(&(sn=" lastName ")(givenName=" firstName ")));distinguishedname,cn,employeeid,mail,givenname,sn,middlename,samaccountname,displayname,department,division,manager;subtree"

oConn := COM_CreateObject("ADODB.Connection")
oComm := COM_CreateObject("ADODB.Command")

COM_Invoke(oConn, "Provider", connProv)
COM_Invoke(oConn, "Open", connOpen)

COM_Invoke(oComm, "ActiveConnection", "+" . oConn)
COM_Invoke(oComm, "Properties", "SearchScope", "2")
COM_Invoke(oComm, "Properties", "Page Size", "500")

COM_Invoke(oComm, "CommandText", Query)
adoExecute := COM_Invoke(oComm, "Execute")

Loop
{
   If COM_Invoke(adoExecute, "EOF")
      Break
     
   exFields := COM_Invoke(adoExecute, "Fields")
   exField := COM_Invoke(exFields, "Item", "cn")   
   result .= COM_Invoke(exField, "Name") . ": " . COM_Invoke(exField, "Value") . "`r`n"
   COM_Invoke(adoExecute, "MoveNext")
   COM_Release(exField)
}

MsgBox   %   result

COM_Invoke(oConn, "Close")
COM_Release(exFields)
COM_Release(exField)
COM_Release(oConn)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 31st, 2010, 12:13 am 
Offline

Joined: December 13th, 2007, 11:41 pm
Posts: 31
I'm not sure if anyone has posted this type of example, but I could not find it, so here goes. I hope this helps someone trying to solve the ADO riddle for dBase databases. Reading records and updating fields.

I cannot stress enough how much reading the msdn info on ADO helped me figure this out. http://msdn.microsoft.com/en-us/library ... 85%29.aspx

I don't have an example dbf file to share, but assume that wrkorder.dbf contains a unique key field of WKORDNUM (work order number), a bunch of other fields, and two long string fields called NOTE1 and NOTE2 that are (not too surprisingly) for notes. varOurWkNum is just a work order number used to pick a specific record.

In my program, I grab the two notes, remove certain references, put them all at the end of the 2nd note and put an ETA date at the beginning of the 1st note. There's a lot of fancy formatting and frippery at work.

For simplicity, this example will just read the two fields, change them slightly, and write them back.


Code:
;Dbq is the path to the dbf file. (S:\ or whatever) This sConnect is highly dbf oriented (DBASE). (http://www.codeproject.com/KB/database/connectionstrings.aspx#dBASE)
sSource := "SELECT WKORDNUM,NOTE1,NOTE2 FROM " . "wrkorder.dbf" . " WHERE WKORDNUM = '" . varOurWkNum . "'"
sConnect := "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=S:\;"

COM_Init() ; (Initialize the process, start the motor, on your mark)
prs :=  COM_CreateObject("ADODB.Recordset") ; define prs as a Recordset object, ready to be acted upon

;Define properties of recordset that tell how it will operate (BEFORE recordset opened) (numbers from w3schools.com/ado/ado_ref_recordset.asp ).
COM_Invoke(prs, "CursorLocation=", 3) ; adUseClient = 3 , local (not on server) use of data
COM_Invoke(prs, "CursorType=", 0) ; adOpenForwardOnly = 0 , cursor will not go backward (I don't need to in this case)
COM_Invoke(prs, "LockType=", 3) ; adLockOptimistic = 3 , Not entirely clear on this, but won't lock out others entirely?

COM_Invoke(prs, "Open", sSource, sConnect) ; Open the recordset, if any, using the source and connect string from above.

Loop
{
   If  COM_Invoke(prs, "EOF")
      Break ; no fields? no match? (not sure) checking for end of fields
   pFields   := COM_Invoke(prs, "Fields") ; Get all the fields (together) in the current row of the recordset
   ; The below are out of order, just to prove it didn't matter. First field index is 0.
        ; You could loop through these, as in other examples, but to me this saves steps by defining the variables as they come.
   pField := COM_Invoke(pFields, "Item", 2) , varNote2 := COM_Invoke(pField, "Value") , COM_Release(pField)
   pField := COM_Invoke(pFields, "Item", 0) , varWorkyNum := COM_Invoke(pField, "Value") , COM_Release(pField)
   pField := COM_Invoke(pFields, "Item", 1) , varNote1 := COM_Invoke(pField, "Value") , COM_Release(pField)

   ;Add ETAXXXX in front of Note1 and NOETAXXXX at end of Note2
        varNote1 := "ETAXXXX" . varNote1
        varNote2 .= "NOETAXXXX"

   ;This does the actual value changing of the individual field in this record. 1st part defines/addresses, 2nd part changes, 3rd part releases.
   pField := COM_Invoke(pFields, "Item", 1) , COM_Invoke(pField, "Value=", varNote1) , COM_Release(pField)
   pField := COM_Invoke(pFields, "Item", 2) , COM_Invoke(pField, "Value=", varNote2) , COM_Release(pField)

   COM_Invoke(prs, "Update") ; Is this even necessary? Works without it I think. Anyone know?
   COM_Release(pFields) ; Release the recordset row (group of fields).
   COM_Invoke(prs, "MoveNext") ; Move to next row, if multirow
}
COM_Invoke(prs, "Close") ; Close the recordset
COM_Release(prs) ; Release the resources/memory (afaik)
COM_Term() ; Close the whole COM process (end to Init)


I hope this helps someone shortcut the chasm of ignorance I had to trudge over. If it doesn't make sense, steep yourself in ADO knowledge.

THANKS SEAN! I really don't think I can know how much I appreciate your COM work, and how excited I am that I finally understand enough to program direct access to my dbf files, rather than going through Access queries as I have been.

Thanks to all others for the contributed code examples.

Toxey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2010, 2:56 pm 
Offline

Joined: December 13th, 2007, 11:41 pm
Posts: 31
Side note to my last post.

Be careful with fields and dbf's that are indexed.

I don't believe we have any method of accessing and modifying NTX indexes on clipper databases through ADO COM, so I'm personally avoiding the problem.

Okay to modify unindexed fields (I hope), and don't delete or add an records. Basically, just sneaky modifications of "unwatched" fields.

So it's less useful than I first said, but it's still darn useful, and I will be on the lookout for a solution to the index problem.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 3rd, 2010, 4:18 pm 
Offline

Joined: July 21st, 2009, 7:13 pm
Posts: 27
I have adapted the examples in this post to pull data from Access Databases.

I am having a bit of trouble figuring out how to write data to a table.
Does anyone have an examples they have adapted, that they would be willing to share.

Thanks


Report this post
Top
 Profile  
Reply with quote  
PostPosted: September 15th, 2010, 2:48 am 
Offline

Joined: September 15th, 2010, 2:31 am
Posts: 4
Hi

The following code attempts to run a stored procedure and work with the record set it returns.

Since i need to set timeout, and i will be adding parameters later, i need to use ADOB.Command.

Problem is that i cant seem to set the CursorType for the recordset and get it to stick.

Code:
sSource  := "sp_databases"
sConnect := "Provider=sqloledb;Data Source=MY-SERVER;Initial Catalog=MY-DATABASE;Integrated Security=SSPI;"


COM_Init()
prs :=   COM_CreateObject("ADODB.Recordset")
pcmd :=   COM_CreateObject("ADODB.Command")
COM_Invoke(pcmd, "CommandText", sSource)
COM_Invoke(pcmd, "CommandType", 4)
COM_Invoke(pcmd, "CommandTimeout", 400)
COM_Invoke(pcmd, "ActiveConnection", sConnect)

;;;;;;;;;;;  Method 1:  ;;;;;;;;;;;;

COM_Invoke(prs, "CursorType", 3)

activeLock := COM_Invoke(prs, "CursorType")
msgbox % activeLock

COM_Invoke(prs, "Open", "+" . pcmd)

activeLock := COM_Invoke(prs, "CursorType")
msgbox % activeLock

;Fails. The CursorType is reset when the connection is opened.

;;;;;;;;;;;  Method 2:  ;;;;;;;;;;;;

COM_Invoke(prs, "Open", "+" . pcmd, ,3)

;Fails with message: Error: Blank Parameter

;;;;;;;;;;;  Method 3:  ;;;;;;;;;;;;

COM_Invoke(prs, "Open", "+" . pcmd, sConnect, 3)

;Fails with message: Cannot change the ActiveConnection property of a Recordset object which has a Command object as its source.

COM_Invoke(prs, "Close")
COM_Release(prs)
COM_Term()


Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2010, 2:21 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
Any way to use the ADO functions to insert data into a database?

I have edited the function so the SQL is INSERT INTO, and not SELECT.

I get error code 0x80040E4D.

DESC: Authentication failed.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2010, 2:36 pm 
Online
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
then the problem is not the call its the credentials are either invalid or your credentials do not have insert privs for your table/database better get with your DBA

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2010, 2:46 pm 
God wrote:
then the problem is not the call its the credentials are either invalid or your credentials do not have insert privs for your table/database better get with your DBA


Im guessing it must be the INSERT priveleges, as I can SELECT fine.

I'm not sure how to grant priveleges to AHK. Its just MS Access accdb file.

I'll see if i can find out.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 22nd, 2010, 5:21 pm 
Online
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
granting or revoking privilidges has nothing to do with ahk and must be done in the database by a user with priviledges to do so

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2010, 8:29 am 
I understand that.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2011, 5:04 pm 
I have this ADO function I use in VBA which executes SQL on the database.

Code:
db_file = [DBLOCATION].Value
    sql = [SQLSUBMIT].Value

    Set conn = New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & db_file & ";" & _
        "Persist Security Info=False"
    conn.Open

    'conn.Execute "DROP TABLE Employees"
    conn.Execute sql


Any idea how to specifically do the "conn.Execute" part in AHK?

I guess its full function is ADODB.Connection.Execute

Ive used Seans code above to retrieve data via select. however I have been unable to use it to CREATE/DROP/INSERT etc.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2011, 5:12 pm 
Online
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Executing a query is executing a query weather is select or create for drop the only difference is permissions expected return What error are you receive Are you sure you have permission to do what You need to do

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 132 posts ]  Go to page Previous  1 ... 5, 6, 7, 8, 9  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], Google Feedfetcher, JamixZol and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group