If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > C and connection to SQL Server

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-04, 16:01
goodolE22 goodolE22 is offline
Registered User
 
Join Date: Feb 2004
Location: NJ
Posts: 37
C and connection to SQL Server

I am not sure whether this forum or the SQL forum is the best place to post my question. I did a search for my question in both forums and got no hits in either. I am currently using tcpdump to collect packet information, i found another programs that formats this information and it is written in c. I would like to go into that program and add some SQL calls to push the needed information to my SQL Server 2000 database. Can any of you guys point me in the direction of the syntax to do this. I did a search on google but haven't found a really good example to explain how this works. My databases name is group16 and my table is Host1Bandwidth. This table has various columns ( Host and Destination IP and MAC Addresses, port, protocol ,etc). I would just like the basic information to be able to add a SQL function in the C code to access the database, log in and push the information to the appropriate column in the table. Any help would be appreciated.

thanks
Evan
Reply With Quote
  #2 (permalink)  
Old 03-24-04, 17:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
I'm not sure how this is different than the last time you asked this question, but my answers would be pretty much the same.

1) Buffer the data in a RAM buffer (this is required)

2) Write a function to put data into the buffer
3) Call this wherever tcpdump writes the data

4) Write another function to use ADO to write the buffer to disk
5) Run the Buffer to SQL function in an asynchronous thread.

-PatP
Reply With Quote
  #3 (permalink)  
Old 03-25-04, 12:04
goodolE22 goodolE22 is offline
Registered User
 
Join Date: Feb 2004
Location: NJ
Posts: 37
sorry about that

Sorry i forgot that i posted that on this forum earlier this month. The idea is essentially the same as before but now we are using tcpdump to capture the info. I downloaded the redhat rpms for iODBC. What do i need to do to set up the connection with my MS SQL database? Like i said before i have a rehdat box that is running tcpdump that is piped through a filter. That filter is written in C. I did a search for ODBC instructions and found a few turorials but i am still confused on how the whole connection works. If i add this to my C code:

set conn=Server.CreateObject("ADODB.Connection")
conn.Open "group16"

what will happen? The name of my SQL server group is W2KServer, group 16 is the name of the database. By using the instruction above how does it know where group16 lives? Do i need to do some configuration through iODBC to make that connection? I found instructions on how to do this if my c program were running on windows and connecting to a MS SQL database (you can add the connection through the control panel), but i have been able to find anything if i am connecting to a MS SQL database on W2K server from a redhat 9 box.

Also i know that you mentioned that i need to push the information from tcpdump into a buffer first and then read from the buffer and outpt to the database, but i am not really sure how to do this. So i am going to concentrate on making the connection to the database first.

Any help would be appreciated
Thanks
Reply With Quote
  #4 (permalink)  
Old 03-25-04, 14:25
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
The Linux-speak for an asynchronous process is a "forked process". You usually start these using the fork() call.

Find out if your school has an approved or supported way for a RedHat box to connect to a SQL database. There are a couple of ways to do this, but they are radically different. I don't have any preference, so pick one that has local support and we can run with it. I'm not familiar with the RedHat iODBC code, so you'll need to find someone that knows how to use it.

You are correct, connecting to the database will be the challenge if you are using Linux instead of one of the Windoze based packet monitors. That is where you need to focus your efforts for now.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On