[Interest] connect sql server via odbc

pengliang(彭亮) pengliang at founder.com
Thu Nov 1 03:21:14 CET 2012


Hi everyone.
I connected MSSQL (on windows) via odbc on linux redhat 64bit.
I executed sql command via isql or tsql(unixODBC) is perfect, but it always fail. 
So, maybe DSN string problem?
Could anybody help me?
Thanks
Ken



Below is odbc and freetds configuration files.

---------------freetds.conf:
[FreeTDS]  
host=172.21.32.20  
port=1433  
tds version=7.2  
client charset = GB2312  
-------------odbcinst.ini
[TDS]  
Description = TDS  
Driver = /usr/local/lib/libtdsodbc.so  
Trace = Yes  
TraceFile=/tmp/odbcinst.log  
UsageCount = 1
----------------odbc.ini:
[SQLSERVER]  
Driver = TDS  
Description = sql server dsn  
Trace = NO  
Server = 172.21.32.20  
Database = Live  
Port = 1433  
TDS_Version = 7.2  
TraceFile=/tmp/sqlserver.log  
----------------------------------Snippets:
QString f3ErpDsn = QString::fromLocal8Bit("Driver={SQLSERVER};server=172.21.32.20;database=Live;uid=inp;pwd=inp;");
QSqlDatabase f3ErpDb= QSqlDatabase::addDatabase("QODBC");
f3ErpDb.setDatabaseName(f3ErpDsn);
// f3ErpDb.setDatabaseName("SQLSERVER");
f3ErpDb.setUserName("inp");
f3ErpDb.setPassword("inp");
QString sqlCmdStr = "select * from dbo.Table_Drilling_Data01 where status=1";
if ( ! f3ErpDb.open() )
{
        qDebug() << f3ErpDb.lastError().text();
        return 1;
}
QSqlTableModel model;
model.setTable("dbo.Table_Drilling_Data01");
model.setFilter("status=3");
model.select();
qDebug() << model.lastError().text();

--------------------------Error messages:
f3ErpDb.setDatabaseName(f3ErpDsn);

1.   If setDatabaseName is f3ErpDsn error message is:
"QODBC3: Unable to connect", "[unixODBC][Driver Manager]Data source name not found, and no default driver specified")
I had defined SQLSERVER in odbc.ini. Why it said can not find it?

2.   But if I changed f3ErpDb.setDatabaseName("SQLSERVER");, error message is:
"[FreeTDS][SQL Server]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 (""): Data type 0x00 is unknown. QODBC3: Unable to execute statement"






More information about the Interest mailing list