LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 08: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, 02: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,552

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

http://www.ethereal.com/
 
Old 10-19-2009, 03: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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
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, 01: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, 01:56 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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, 02: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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
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, 02: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, 02:13 PM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 04:21 PM.
 
Old 10-21-2009, 02: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:11 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