Page 1 of 1

Excel, ODBC and SQLConfigDataSource

Posted: Tue Oct 06, 2015 12:08 pm
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

Re: Excel, ODBC and SQLConfigDataSource

Posted: Tue Oct 06, 2015 12:47 pm
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

Re: Excel, ODBC and SQLConfigDataSource

Posted: Wed Oct 07, 2015 7:31 am
by dige
Thx bbanelli, for that hint. But since PB supports ODBC databases, I prefer to use the PB command set..

Re: Excel, ODBC and SQLConfigDataSource

Posted: Wed Oct 07, 2015 11:08 am
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

Re: Excel, ODBC and SQLConfigDataSource

Posted: Wed Oct 07, 2015 9:33 pm
by linkerstorm
Hi.

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

Regards.

Re: Excel, ODBC and SQLConfigDataSource

Posted: Tue Oct 20, 2015 11:24 am
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

Re: Excel, ODBC and SQLConfigDataSource

Posted: Tue Oct 20, 2015 12:30 pm
by ts-soft
Have you used: Unicode and X86 ?

Re: Excel, ODBC and SQLConfigDataSource

Posted: Tue Oct 20, 2015 12:34 pm
by Kiffi
Hello Thomas,

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

Thanks & Greetings ... Peter