LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2009, 09:22 AM   #1
wiener
LQ Newbie
 
Registered: Jun 2009
Posts: 22

Rep: Reputation: 0
C program to connect to MS SQL server


Hi folks,
I need to write a C client program that communicates with a Microsoft SQL server.
I need help with finding the actual content of the messages that flow between the client and the server, and best - if there is aleady such a code which I can re-use.
Thanks in advance,
Moses.
 
Old 10-19-2009, 03:51 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,497

Rep: Reputation: 90
Sounds like you need a packet-sniffer?

http://www.ethereal.com/
 
Old 10-19-2009, 04:39 AM   #3
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
C? How about PERL? There's a great write up over there on perlmonks.

If you need something that can run on the command line, I could suggest maybe PHP, as well. But for C, I don't know.

Good Luck!
 
Old 10-21-2009, 02:22 PM   #4
wiener
LQ Newbie
 
Registered: Jun 2009
Posts: 22

Original Poster
Rep: Reputation: 0
Reply:

Quote:
Originally Posted by xeleema View Post
C? How about PERL? There's a great write up over there on perlmonks.

If you need something that can run on the command line, I could suggest maybe PHP, as well. But for C, I don't know.

Good Luck!
Well, thanks for the reply. Yet, I have to do it in C. I've got the document that describes the protocol of thoe messages that flow bwetween the client and the server, and I'm implementing them as a client software.
The doc is the spec of "Tabular Data Stream Protocol" Version 4.2 by Microsoft.
 
Old 10-21-2009, 02:56 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
does mssql allow querying from the command line like mysql ?

i would assume it would be just as easy as implimenting a few system() calls.
 
Old 10-21-2009, 03:01 PM   #6
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
MySQL Queries from the CLI

I don't think system() would have the facility to do that. It depends on two things;

1. Do you have a MySQL API that you're going through?

2. Are you accessing a local MySQL database, or a remote one?

That being said, I know that you can throw commands at a MySQL DB like this;

Code:
mysql -u username -p -e "create database exampledb"
If you have a really complicated query, you can throw it into a file and run it as needed, too;

Code:
mysql -u username -p exampledb < query.sql
Hope this helps!
 
Old 10-21-2009, 03:04 PM   #7
wiener
LQ Newbie
 
Registered: Jun 2009
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by schneidz View Post
does mssql allow querying from the command line like mysql ?

i would assume it would be just as easy as implimenting a few system() calls.
The messages in MS SQL are binary messages, unlike the so-much-friendly
mySql, so I guess there is no easy way to use the 'system' call.
 
Old 10-21-2009, 03:13 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
Quote:
Originally Posted by xeleema View Post
I don't think system() would have the facility to do that. It depends on two things;

1. Do you have a MySQL API that you're going through?

2. Are you accessing a local MySQL database, or a remote one?

That being said, I know that you can throw commands at a MySQL DB like this;

Code:
mysql -u username -p -e "create database exampledb"
If you have a really complicated query, you can throw it into a file and run it as needed, too;

Code:
mysql -u username -p exampledb < query.sql
Hope this helps!
i know this is off-topic but why wouldnt this work:
Code:
#include <stdio.h>
main()
{
 system("mysql -u username -p exampledb < query.sql");
/*/
the original poster already explained why this wouldnt work:
 system("mssql -u username -p exampledb < query.sql");
/*/
}

Last edited by schneidz; 10-22-2009 at 05:21 PM.
 
Old 10-21-2009, 03:17 PM   #9
wiener
LQ Newbie
 
Registered: Jun 2009
Posts: 22

Original Poster
Rep: Reputation: 0
Reply:

It would work for mysql provided that I have the mysql client program installed on my machine.
Yet, I need to implement a client for Microsoft SQL - which as far as I know, has no line command client program for their DB server.
 
  


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
SQL Anywhere to connect to MySQL Server crackyblue General 0 06-22-2009 08:42 PM
Wrote java program and can't connect to sql database mokoena Programming 1 07-12-2008 11:01 AM
Connect to MS SQL Server from linux C++ ? skosanba Linux - Software 0 08-14-2006 09:05 AM
Connect to ms sql server from linux RH saustin99 Linux - Newbie 1 02-17-2006 06:07 PM
Connect to SQL Server dhome Linux - Software 1 03-08-2004 01:56 PM


All times are GMT -5. The time now is 12: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration