[erlang-questions] Some problem abount odbc?

sky <>
Wed Dec 1 03:28:27 CET 2010


Dear all,

When i used odbc to connect a sql server database, i met some 
problem:all string data which returned by odbc:sql_query() has been 
convert to binary,
even though i set option binary_strings=off, what's the matter? And how 
could i get the string format?

the original string is "192.168.0.4", and the convert binary is 
<<49,0,57,0,50,0,46,0,49,0,54,0,56,0,46,0,48,0,46,0,52,0>>. and the 
datatype of the string is nvarchar。

regards.

this the sorce code:
Code:

-module(server_config).
-export([]).
-compile(export_all).

start() ->
     odbc:start(),
     case odbc:connect("DSN=ErlangDSN;UID=wahaha;PWD=123456",
             []) of
    {ok, RefConnection} ->
       odbc:sql_query(RefConnection,
                 "select top 1 Name, IP, Port from server_list");
    {error, Reason} ->
       io:format("fail to connect database:~p~n", Reason),
       {error, Reason}
     end.



this the result:
Code:
server_config:start().
{selected,["Name","IP","Port"],
           [{<<80,0,86,0,69,0,75,109,213,139,49,0>>,
<<49,0,57,0,50,0,46,0,49,0,54,0,56,0,46,0,48,0,46,0,52,0>>,
             9201}]}


More information about the erlang-questions mailing list