ich möchte auf eine Access-Datenbank per ODBC zugreifen und verwende folgenden Code, der unter PB 5.60 und früher
tadellos funktioniert hat:
Code: Alles auswählen
EnableExplicit
#ODBC_ADD_DSN = 1
Procedure StringChangeChar(*pzString, piLen.i, pcSuch.c, pcErsetz.c)
Protected.i i = 0
Protected *cChar.Character = *pzString
For i = 0 To piLen
If *cChar\c = pcSuch
*cChar\c = pcErsetz
EndIf
*cChar + SizeOf(Character)
Next i
EndProcedure
Procedure.i DB_Open()
Protected.i iHandle
Protected.s zErr,
zFile,
zName,
zDriver,
zExt,
zAttributes,
zUser,
zPass
Protected.l lErr
Protected *ErrMsg
zFile = GetTemporaryDirectory() + "TEST.MDB"
zName = GetFilePart(zFile)
zExt = GetExtensionPart(zFile)
zName = Left(zName, Len(zName) - Len(zExt) - 1)
zDriver = "Microsoft Access Driver (*.mdb)"
If FileSize(zFile) = -1
zAttributes = "CREATE_DB=" + zFile + " General"
zAttributes + ";UID=" + zUser
zAttributes + ";PWD=" + zPass + ";"
StringChangeChar(@zAttributes, Len(zAttributes), ';', 0)
iHandle = SQLConfigDataSource_(0, #ODBC_ADD_DSN, zDriver, zAttributes)
EndIf
zAttributes = "Server=APServer;Description=" + zName
zAttributes + ";DSN=" + zName
zAttributes + ";DBQ=" + zFile
zAttributes + ";UID=" + zUser
zAttributes + ";PWD=" + zPass + ";"
StringChangeChar(@zAttributes, Len(zAttributes), ';', 0)
iHandle = SQLConfigDataSource_(0, #ODBC_ADD_DSN, zDriver, zAttributes)
If iHandle
iHandle = OpenDatabase(#PB_Any, zName, zUser, zPass, #PB_Database_ODBC)
If iHandle = 0
Debug DatabaseError()
ProcedureReturn 0
EndIf
Else
*ErrMsg = AllocateMemory(256)
SQLInstallerError_(1, @lErr, *ErrMsg, 255, #Null)
Debug PeekS(*ErrMsg, -1, #PB_Ascii)
FreeMemory(*ErrMsg)
ProcedureReturn 0
EndIf
ProcedureReturn iHandle
EndProcedure
UseODBCDatabase()
DB_Open()
Ich verwende die x86er Version von PB auf Windows 10.
Weiß jemand Rat?