freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
[freetds] libtds - setting tds version and port number
- From: Ed Freeberg <freetds AT lvdcasino.com>
- To: FreeTDS AT lists.ibiblio.org
- Cc:
- Subject: [freetds] libtds - setting tds version and port number
- Date: Mon, 30 Aug 2004 15:39:11 -0500
Hello:
I'm trying to get a "Hello World" program to connect to my MS-SQL 7.0 server. Based on my experience using freetds with PHP, TDS version 4.2 works for me.
freetds was configured as:
./configure --prefix=/usr/local/freetds --with-tdsver=4.2 --enable-msdblib
here's my program:
<snip>
//
// prototype connect to ms-sql server
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <sys/param.h>
#include <sqlfront.h>
#include <sqldb.h>
int main(int argc, char **argv) {
char SERVER[512];
char DATABASE[512];
char USER[512];
char PASSWORD[512];
LOGINREC *login;
TDSLOGIN *tdslogin;
DBPROCESS *dbproc;
strcpy(SERVER, "192.168.0.1");
strcpy(DATABASE, "mydb");
strcpy(USER, "myuser");
strcpy(PASSWORD, "mypass");
dbinit();
dbsetversion(DBVERSION_42);
login = dblogin();
DBSETLPWD(login, PASSWORD);
DBSETLUSER(login, USER);
DBSETLAPP(login, "sql");
dbproc = dbopen(login, SERVER);
if (!dbproc) {
fprintf(stderr, "Unable to connect to %s\n", SERVER);
return 1;
}
if (strlen(DATABASE)) {
dbuse(dbproc, DATABASE);
}
dbcmd(dbproc, "SELECT * FROM #mytable");
dbsqlexec(dbproc);
while (dbresults(dbproc) != NO_MORE_RESULTS) {
fprintf(stdout, "Found");
}
dbexit();
}
</snip>
...which is based on copying some of the examples and other snippets found on the web.
When I execute this program, I get:
[ed@neo sqltest]# ./sql
src/tds/login.c: tds_connect: 192.168.0.1:4000: Connection refused
Unable to connect to 192.168.0.1
So, obviously it's confused about which protocol and port it's supposed to be using (it's supposed to speak 4.2 to port 1433/tcp).
I've googled and searched the archives and the included examples, but haven't figured out how to tell it to use 4.2 (and port 1433) properly. Any help would be much appreciated.
Other info about the platform I'm compiling on:
RedHat 9
gcc-3.2.2-5
freetds-0.62.4
Thanks,
Ed
-
[freetds] libtds - setting tds version and port number,
Ed Freeberg, 08/30/2004
- Re: [freetds] libtds - setting tds version and port number, Ed Freeberg, 08/30/2004
-
Re: [freetds] libtds - setting tds version and port number,
Jon Foster, 08/30/2004
-
Re: [freetds] libtds - setting tds version and port number,
Ed Freeberg, 08/30/2004
- Re: [freetds] libtds - setting tds version and port number, Alex Kiesel, 08/30/2004
-
Re: [freetds] libtds - setting tds version and port number,
Ed Freeberg, 08/30/2004
Archive powered by MHonArc 2.6.24.