MS SQL 2000 access using C++ in linux
Hello Everbody,
I want to access MS SQL 2000 database using my C++ program (OTL used). I tried using the FreeTdS driver. Connection , Insert and Update staement are working but select statement is not working. Select statment is returning a "Incompatible datatype exception" always. Syntax and all other things are right. Same select query is working fine using isql. freetds is also working fine. Plz tell me a soln... I need it urgently... Plz reply, Waiting, Gourav |
We need more information:
1. Do you know which specific "select" statement is failing? 2. Do you know which specific C++ variable(s) that you're binding is causing the failure? 3. Is the error coming from freeTDS or from SQL 2000? 4. Have you used SQL Trace or any of the SQL 2000 trace/logging tools to determine if the query is ever making it past of your client out to SQL 2000 and, if so, exactly what SQL 2000 doesn't like about it? 5. Have you posted a query to the FreeTDS news group? In my experience, they are *very* helpful and *very* responsive. Good luck .. PSM |
select query now Working fine
Hello Everybody,
hey paulsm4 thanks for replying... I got the solution for that select statement problem.. Thanks to the reply from Sergei Kuchin... I was not using otl_implicit_select when querying, o.open(1,"select * from table",db, //->>>> here ->> otl_implicit_select <<<<--------///) Coz on windows the same query without otl_implicit_select argument was working perfectly. Now the problem is solved... |
Glad you got it resolved!
Aha - so it was actually an OTL problem!
Anyway, I'm glad you got it resolved! Your .. PSM |
hello
hi paulsm4,
No that is not an OTL problem.... the code is running fine on windows ODBC driver... But in linux I am using FreeTDS to commu.,,with MS SQL. So the way of coding slightly changes... which I came to know... its upto the implementors of the driver...to decide... Thanks for replying.... With lots of regards... Gourav |
Hi Gaurav,
I am trying to do the same thing but not ablt to access mssql from c++ through freetds. Can you please guide me how to do that. I am able to conect through C. Thanks, Nidhi |
hi nidhi,
What interface did you use in C++? try using otl 4.0 for C++. http://otl.sourceforge.net hey, r u from Belgaum? Gourav |
Hi Gaurav,
thanks for looking into my problem.I am using otl 4.0 only, i copied a sample program and complied it with this command g++ test11.cpp -o test11 -lodbc the compilation is successful but the output file gives error "[unixODBC]Could not find Servername parameter' I created a dsn and tested it with isql command and its connection to my sql server but the same dsn is not working in c++ program. here is my server configuration files detail /etc/odbc.ini [MySQL-test] Description = MySQL database test Driver = MySQL Server = 192.168.1.253 Database = agent UID = root PWD = intercom Port = 3306 [mssql] Description = TDSDriver Driver = TDSDriver Servername = 192.168.1.54 Database = DigitalkDB UID = sa PWD = nidhi Port = 1433 /usr/local/freetds/etc/freetds.conf A typical Microsoft SQL Server 7.0 configuration [mssql] host = 192.168.1.54 port = 1433 tds version = 7.0 # If you get out of memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # (Microsoft servers sometimes pretend TEXT columns are # 4 GB wide!) If you have this problem, try setting # 'text size' to a more reasonable limit # text size = 8096 I am from Indai. Can you please tell me where i am making a mistake. Nidhi |
hi nidhi,
can you please show me your c++ program and the odbcinst.ini file? and which dsn are u trying to connect using isql? please change Servername from 192.168.1.54 to mssql in your [mssql] dsn( ODBC-freeTDS configuration ) and try running your program. Hey BTW .. belgaum is in india.. ;) Gourav |
Hi Gaurav,
thanks for the reply.right now i am not in office will send you the details tomorrow morning. Sorry i read city name incorrectly. can i chat with you on messenger for this.my messenger id is nidhimongia@yahoo.com nidhimongia@hotmail.com thanks, nidhi |
Hi nidhi,
its almost 3:50 am here in my place (US). time to sleep.. but anyway we can chat about the problem sometimes tommorrow if we catch each other online ..my id gdtilve@yahoo.com. regards Gourav |
Hi Gaurav,
thanks, i added you on yahoo. Nidhi |
Hi Gaurav,
here is the structure of odbcinst.ini file of my server [PostgreSQL] Description = ODBC for PostgreSQL Driver = /usr/lib/libodbcpsql.so Setup = /usr/lib/libodbcpsqlS.so FileUsage = 1 [demo] Driver = OOB Description = Easysoft ODBC-ODBC Bridge demo data source SERVERPORT = demo.easysoft.com:8888 TARGETDSN = pubs LOGONUSER = demo LOGONAUTH = easysoft TargetUser = demo TargetAuth = easysoft FileUsage = 1 [OOB] Description = Easysoft ODBC-ODBC Bridge Driver = /usr/local/easysoft/oob/client/libesoobclient.so Setup = /usr/local/easysoft/oob/client/libesoobsetup.so FileUsage = 1 [MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc.so FileUsage = 1 [TDSDriver] Description = tds driver Driver = /usr/local/lib/libtdsodbc.so Setup = /usr/lib/libtdsS.so FileUsage = 1 CPTimeout = CPReuse = ~ i am using mssql dsn to connect vis isql. sample c++ program: #include <iostream> using namespace std; #include <stdio.h> #define OTL_ODBC // Compile OTL 4.0/ODBC #include <otlv4.h> // include the OTL 4.0 header file otl_connect db; // connect object void insert() // insert rows into table { otl_stream o(50, // buffer size "insert into test_tab values(12345678900000000+convert(numeric,:f1<int>),:f2<char[31]>)", // SQL statement db // connect object ); char tmp[32]; for(int i=1;i<=100;++i){ sprintf(tmp,"Name%d",i); o<<i<<tmp; } } void select() { otl_stream i; i.set_column_type(1,otl_var_char,40); // use a string(40) instead of default double i.open(50, // buffer size "select * from test_tab " "where f1>=12345678900000000+convert(numeric,:f11<int>) " " and f1<=12345678900000000+convert(numeric,:f12<int>)*2", // SELECT statement db // connect object ); // create select stream char f1[40]; char f2[31]; i<<8<<8; // assigning :f11, :f12 = 8 // SELECT automatically executes when all input variables are // assigned. First portion of output rows is fetched to the buffer while(!i.eof()){ // while not end-of-data i>>f1>>f2; cout<<"f1="<<f1<<", f2="<<f2<<endl; } i<<4<<4; // assigning :f11, :f12 = 4 // SELECT automatically executes when all input variables are // assigned. First portion of output rows is fetched to the buffer while(!i.eof()){ // while not end-of-data i>>f1>>f2; cout<<"f1="<<f1<<", f2="<<f2<<endl; } } int main() { otl_connect::otl_initialize(); // initialize ODBC environment try{ cout <<"connecting...."; db.rlogon("uid=sa;pwd=nidhi;dsn=mssql"); // connect to ODBC cout <<"success"; otl_cursor::direct_exec ( db, "drop table test_tab", otl_exception::disabled // disable OTL exceptions ); // drop table otl_cursor::direct_exec ( db, "create table test_tab(f1 numeric, f2 varchar(30))" ); // create table insert(); // insert records into table select(); // select records from table } catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error cerr<<p.var_info<<endl; // print out the variable that caused the error } db.logoff(); // disconnect from ODBC return 0; } here i commented out everything just trying to make connection with the database.. Please let me know where i am making mistake. Regards, Nidhi |
Hi nidhi,
Did u try changing Servername from "192.168.1.54" to "mssql" in your [mssql] dsn( ODBC-freeTDS configuration )as shown below and try running your program. ---odbc.ini --- [mssql] Description = TDSDriver Driver = TDSDriver Servername = mssql Database = DigitalkDB UID = sa PWD = nidhi Port = 1433 Gourav |
Hi Gaurav,
yes i did, but still its showing the same error. Nidhi |
All times are GMT -5. The time now is 07:39 AM. |