LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-05-2005, 06:36 AM   #1
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Rep: Reputation: 15
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
 
Old 02-05-2005, 07:32 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 02-06-2005, 11:36 PM   #3
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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...
 
Old 02-07-2005, 10:55 AM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Glad you got it resolved!

Aha - so it was actually an OTL problem!

Anyway, I'm glad you got it resolved!

Your .. PSM
 
Old 02-07-2005, 11:23 PM   #5
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 07-14-2006, 03:07 AM   #6
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
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
 
Old 07-14-2006, 01:33 PM   #7
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 07-15-2006, 03:18 AM   #8
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
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
 
Old 07-16-2006, 04:25 AM   #9
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 07-16-2006, 04:34 AM   #10
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
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
 
Old 07-16-2006, 04:42 AM   #11
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 07-16-2006, 11:11 AM   #12
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
Hi Gaurav,

thanks, i added you on yahoo.

Nidhi
 
Old 07-17-2006, 12:22 AM   #13
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
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:tl_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
 
Old 07-17-2006, 12:55 AM   #14
gourav
LQ Newbie
 
Registered: Feb 2005
Location: USA
Distribution: Debian
Posts: 22

Original Poster
Rep: Reputation: 15
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
 
Old 07-17-2006, 04:10 AM   #15
nidhi
Member
 
Registered: Mar 2005
Posts: 30

Rep: Reputation: 15
Hi Gaurav,

yes i did, but still its showing the same error.

Nidhi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a database manager for linux that is compatable with M$ Access and SQL? enigma Z Linux - Software 2 08-27-2004 08:50 PM
SQL Server 2000 assatron Linux - Software 4 08-19-2004 03:02 PM
Mergeant 0.12.1 & SQL 2000 Modify Linux - Software 0 12-29-2003 04:27 AM
Connecting to Microsoft SQL Server 2000 sput Linux - Distributions 7 08-25-2003 09:06 PM
PHP and MS SQL Server 2000 balfred Programming 0 03-24-2003 03:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration