HDBC with SQL Server / OBDC

View: New views
7 Messages — Rating Filter:   Alert me  

HDBC with SQL Server / OBDC

by Morten Holm Pedersen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

am trying to do a simple DB connection from Haskell to a SQL Server 2005
(on Windows obviously). The DSN name ("Nylon") works from C++ but when
running the below example (or any other I can think of) ghci crashes.
Does anyone know a resolution for this or where the problem can possible
be ?


GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :m Database.HDBC
Prelude Database.HDBC> :m + Database.HDBC.ODBC
Prelude Database.HDBC Database.HDBC.ODBC>  do { conn <- connectODBC
"DSN=Nylon"; xs <- getTables conn; putStr $ head xs; }
Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package bytestring-0.9.0.1 ... linking ... done.
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Loading package mtl-1.1.0.0 ... linking ... done.
Loading package HDBC-1.1.4 ... linking ... done.
Loading package HDBC-odbc-1.1.4.3 ... linking ... done.
CRASH !!!




Thanks
Morten


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by Andrew Appleyard-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Morten,

On 26/05/2008 2:24 AM, you wrote:
> am trying to do a simple DB connection from Haskell to a SQL Server 2005
> (on Windows obviously). The DSN name ("Nylon") works from C++ but when
> running the below example (or any other I can think of) ghci crashes.
> Does anyone know a resolution for this or where the problem can possible
> be ?

I had the same problem last week.  I found that GHCi would silently
crash, but GHC would give link errors on the foreign imported functions
from the odbc32 library.  Changing the calling convention from 'ccall'
to 'stdcall' for the 16 'sql.h' imports fixed the problem for me, but
I'm not convinced that's the 'right way' to fix it (ccall is surely the
appropriate calling convention for using ODBC on Unix, for example).

> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> Prelude> :m Database.HDBC
> Prelude Database.HDBC> :m + Database.HDBC.ODBC
> Prelude Database.HDBC Database.HDBC.ODBC>  do { conn <- connectODBC
> "DSN=Nylon"; xs <- getTables conn; putStr $ head xs; }
> Loading package array-0.1.0.0 ... linking ... done.
> Loading package containers-0.1.0.1 ... linking ... done.
> Loading package bytestring-0.9.0.1 ... linking ... done.
> Loading package old-locale-1.0.0.0 ... linking ... done.
> Loading package old-time-1.0.0.0 ... linking ... done.
> Loading package mtl-1.1.0.0 ... linking ... done.
> Loading package HDBC-1.1.4 ... linking ... done.
> Loading package HDBC-odbc-1.1.4.3 ... linking ... done.
> CRASH !!!

Regards,
Andrew
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by greg-128 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 25 May 2008, Morten Holm Pedersen wrote:

> am trying to do a simple DB connection from Haskell to a SQL Server 2005
> (on Windows obviously). The DSN name ("Nylon") works from C++ but when
> running the below example (or any other I can think of) ghci crashes.

I have been having the same (or similar) problem with HDBC and
SQL Server. I have no problem using HDBC and SQLite on Windows,
and also have no problems with perl's DBI and DBD::ODBC
connecting to the SQL Server database with the same DSN.

But I don't know where to point the finger, and I don't know what
to do next. It does seem strange that there is no error message
when ghci crashes.

--
Dr Bean                      Autonomous language learning:
                             My next project after overseeing
                             the making of laborers into athletes.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by John Goerzen-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sunday 25 May 2008 11:24:20 am Morten Holm Pedersen wrote:
> am trying to do a simple DB connection from Haskell to a SQL Server 2005
> (on Windows obviously). The DSN name ("Nylon") works from C++ but when
> running the below example (or any other I can think of) ghci crashes.
> Does anyone know a resolution for this or where the problem can possible
> be ?

First off, I'd suggest separating out the steps in your do block to
individual pieces so you can isolate where the crash is.  Also, what sort of
error message do you get when the crash occurs?  And are you using a MingW
GHC?

-- John
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by Olivier Boudry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, May 25, 2008 at 8:04 PM, Andrew Appleyard <andrew.appleyard@...> wrote:
I had the same problem last week.  I found that GHCi would silently crash, but GHC would give link errors on the foreign imported functions from the odbc32 library.  Changing the calling convention from 'ccall' to 'stdcall' for the 16 'sql.h' imports fixed the problem for me, but I'm not convinced that's the 'right way' to fix it (ccall is surely the appropriate calling convention for using ODBC on Unix, for example).

If the calling convention is stdcall on Windows and ccall on other OS then it should be defined based on the OS. This can be done by updating the .hsc files to define the calling convention as a "macro" depending on the OS type.

#ifdef mingw32_HOST_OS
#let CALLCONV = "stdcall"
#else
#let CALLCONV = "ccall"
#endif

And the foreign import should use CALLCONV instead of ccall.

This should make it work on Windows and not break it on Linux.

Olivier.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by Morten Holm Pedersen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John Goerzen wrote:

> On Sunday 25 May 2008 11:24:20 am Morten Holm Pedersen wrote:
>> am trying to do a simple DB connection from Haskell to a SQL Server 2005
>> (on Windows obviously). The DSN name ("Nylon") works from C++ but when
>> running the below example (or any other I can think of) ghci crashes.
>> Does anyone know a resolution for this or where the problem can possible
>> be ?
>
> First off, I'd suggest separating out the steps in your do block to
> individual pieces so you can isolate where the crash is.  Also, what sort of
> error message do you get when the crash occurs?  And are you using a MingW
> GHC?
>
> -- John

I am running it in plain Windows (from cmd). The text in the mail is the
full communication from the system - ie. just stops without any message.
Sometimes Windows gives an errors a well.

The do was just an attemp to illustrate. Really I just need to do
con=connectODBC "DSN=Nylon"
and then write "con" on the GHCi prompt to crash the system.


Morten

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: HDBC with SQL Server / OBDC

by Andrew Appleyard-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, May 28, 2008 at 12:46 AM, Olivier Boudry
<olivier.boudry@...> wrote:

> If the calling convention is stdcall on Windows and ccall on other OS then
> it should be defined based on the OS. This can be done by updating the .hsc
> files to define the calling convention as a "macro" depending on the OS
> type.
>
> #ifdef mingw32_HOST_OS
> #let CALLCONV = "stdcall"
> #else
> #let CALLCONV = "ccall"
> #endif
>
> And the foreign import should use CALLCONV instead of ccall.
>
> This should make it work on Windows and not break it on Linux.

Thanks Olivier, that's neater than I thought.  I'll put a patch together.

-- Andrew
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@...
http://www.haskell.org/mailman/listinfo/haskell-cafe