Excel, ODBC and SQLConfigDataSource

Everything else that doesn't fall into one of the other PB categories.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Excel, ODBC and SQLConfigDataSource

Post by dige »

Hi folks,

I use ODBC to read Excel Files. For every new file, it's necessary to create a DSN first, to define the datasource.

But (may be) since PB5.40, the command: SQLConfigDataSource_() allways failed.

What was changed and what can I do now?

Ciao dige
"Daddy, I'll run faster, then it is not so far..."
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Excel, ODBC and SQLConfigDataSource

Post by bbanelli »

Hi, I don't know answer to your question, but perhaps you could consider accessing Excel via COM?

http://www.forums.purebasic.com/english ... 33#p462333
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Excel, ODBC and SQLConfigDataSource

Post by dige »

Thx bbanelli, for that hint. But since PB supports ODBC databases, I prefer to use the PB command set..
"Daddy, I'll run faster, then it is not so far..."
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Excel, ODBC and SQLConfigDataSource

Post by Kiffi »

dige wrote:But (may be) since PB5.40, the command: SQLConfigDataSource_() allways failed.
Bad news! :cry:
dige wrote:What was changed and what can I do now?
I'm also interested in a solution.

Here is the (faulty) code:

Code: Select all

Procedure.i AddConnection(driver$, connectString$) 
  Protected result, base, *mem.CHARACTER, *ptr.CHARACTER, len, i
  If driver$ And connectString$
    len = Len(connectString$)
    base = AllocateMemory((len + 2)<<(SizeOf(CHARACTER)-1))
    If base
      *mem = base
      *ptr = @connectString$
      ;Switch all ; for nulls.
      For i = 1 To len
        If *ptr\c <> ';'
          *mem\c = *ptr\c
        EndIf
        *mem + SizeOf(CHARACTER)
        *ptr + SizeOf(CHARACTER)
      Next
      result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, driver$, base) 
      FreeMemory(base)
      If result 
        ProcedureReturn 1 
      EndIf 
    EndIf
  EndIf
EndProcedure 
Procedure.i RemoveConnection(Driver.s,DSN.s) 
  Protected Result
  Result=SQLConfigDataSource_(0,#ODBC_REMOVE_DSN,Driver,"DSN="+DSN) 
  If Result 
    ProcedureReturn 1 
  EndIf 
EndProcedure
Thanks in advance & Greetings ... Peter
Hygge
linkerstorm
User
User
Posts: 47
Joined: Sun Feb 18, 2007 11:57 am

Re: Excel, ODBC and SQLConfigDataSource

Post by linkerstorm »

Hi.

Have you tried to launch your app with admin rights in PB IDE (Compiler Options) ?

Regards.
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Excel, ODBC and SQLConfigDataSource

Post by Kiffi »

linkerstorm wrote:Have you tried to launch your app with admin rights in PB IDE (Compiler Options) ?
the code above works fine with PB V5.31. Since V5.4 it fails. So i think it's not a rights problem.

i guess the code fails her:

Code: Select all

result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, driver$, base)
It would be nice, if someone, who has a better knowledge about the parameter, can take a deeper look?

Thanks in advance & Greetings ... Peter
Hygge
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Excel, ODBC and SQLConfigDataSource

Post by ts-soft »

Have you used: Unicode and X86 ?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Excel, ODBC and SQLConfigDataSource

Post by Kiffi »

Hello Thomas,

thanks for your quick reply! Unicode was the magic word. Now it works as expected. :D

Thanks & Greetings ... Peter
Hygge
Post Reply