cannot connect
Posted in 2003
Topics: General Discussion
hello, we are experiencing a sporadic problem where the database will not allow any new connections. does anyone have a script they run that will connect to the database, do a simple select and then exit? this script would only send mail if there was a problem, otherwise we would never hear from it.... Thanks!
On Mon, 25 Aug 2003 11:23:20 -0400, tomL wrote: Try this ESQL/C program. You'll have to enhance it to do the email but that's rather trivial: Art S. Kagel > hello, > we are experiencing a sporadic problem where the database will not allow > any new connections. does anyone have a script they run that will > connect to the database, do a simple select and then exit? this script > would only send mail if there was a problem, otherwise we would never > hear from it.... > Thanks! <FILE: dbping2.ec> /* dbping2.ec - Improved version! */ /* RCS Header: ----------- $Header: /home/kagel/.mine/RCS/dbping2.ec,v 1.5 2001/12/10 21:11:14 kagel Exp $ RCS Log: -------- $Log: dbping2.ec,v $ Revision 1.5 2001/12/10 21:11:14 kagel Removed outdated comments. Revision 1.4 2001/12/10 20:16:16 kagel Added auto connect to database sysmaster if none provided. Revision 1.2 2001/12/10 20:11:58 kagel Improved. Revision 1.2 2000/11/16 17:30:02 kagel Updated to handle refused connections. Revision 1.1 2000/11/16 17:15:42 kagel Initial revision */ static const char RCSHeader[] = "@(#)$Header: /home/kagel/.mine/RCS/dbping2.ec,v 1.5 2001/12/10 21:11:14 kagel Exp $"; static const char RCSWhat[] = "$What: <@(#) dbping2.ec,v 1.5 > $ $Date: 2001/12/10 21:11:14 $"; static const char RCSCompile[] = "@(#)$cc: " __FILE__ " " __DATE__ " " __TIME__ " $"; /* dbping.ec - try to connect to the default or specified server and report timing. */ #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <sys/signal.h> #include <sys/time.h> #define SQLOK 0 void handler( int signal_num ) ; EXEC SQL include sqlca ; EXEC SQL include datetime ; EXEC SQL include locator ; EXEC SQL include sqltypes ; struct timeval tp, tp1, tp2, tp3 ; int timeout = 5; void usage( char *prog ) { fprintf( stderr, "Usage: %s <ServerName <timeout>>\\n", prog ); } int main(int argc, char *argv[]) { EXEC SQL BEGIN DECLARE SECTION ; string server[1025], connected_name[1025], hostname[1025]; EXEC SQL END DECLARE SECTION ; if (argc >= 2) { if (strcmp( argv[1], "-?" ) == 0 || strcmp( argv[1], "-h" ) == 0 ) { fprintf( stderr, "Usage: %s [[database/server spec] [timeout]]\\n", argv[0] ); return 0; } if ( strlen( argv[1] ) > 1024) { fprintf( stderr, "Invalid server: %s.\\n", argv[1] ); usage( argv[0] ); exit(1); } strcpy( server, argv[1] ); } else sprintf( server, "sysmaster@%s", getenv( "INFORMIXSERVER" ) ); if (argc >= 3) timeout = atol( argv[2] ); else timeout = 5; if (!timeout) timeout = 5; /* set a signal handler for the timeout timer */ signal( SIGALRM, handler ) ; alarm(0) ; gettimeofday( &tp, (struct timezone *)NULL ); fprintf( stderr, "%s started with %d second timeout at %s\\n", argv[0], timeout, asctime( localtime( &tp.tv_sec ) ) ); alarm( timeout ); EXEC SQL CONNECT TO :server; alarm( 0 ); gettimeofday( &tp2, (struct timezone *)NULL ); tp3.tv_sec = tp2.tv_sec - tp.tv_sec; tp3.tv_usec = tp2.tv_usec - tp.tv_usec; if (tp3.tv_usec < 0) { tp3.tv_sec--; tp3.tv_usec += 1000000; } if (sqlca.sqlcode < 0) { fprintf( stderr, "Connection failed in %d.%06.6d seconds, at: %s", tp3.tv_sec, tp3.tv_usec, asctime( localtime( &tp2.tv_sec ) ) ); fprintf( stderr, "Engine is available but connection failed: %d, %d.\\n", sqlca.sqlcode, sqlca.sqlerrd[1] ); return 2; } fprintf( stderr, "Connection successful in %d.%06.6d seconds, at: %s", tp3.tv_sec, tp3.tv_usec, asctime( localtime( &tp2.tv_sec ) ) ); again: EXEC SQL SELECT cf_effective, dbinfo( 'dbhostname' ) INTO :connected_name, :hostname FROM sysmaster:sysconfig WHERE cf_name = 'DBSERVERNAME'; if (sqlca.sqlcode == -349) { EXEC SQL DATABASE sysmaster; goto again; } else if (sqlca.sqlcode != 0) { fprintf( stderr, "Error getting servername: %d, ISAM=%d.\\n", sqlca.sqlcode, sqlca.sqlerrd[1] ); return 1; } else fprintf( stderr, "Actually connected to: %s on %s.\\n", connected_name, hostname ); return 0; } void handler( int signal_num ) { gettimeofday( &tp2, (struct timezone *)NULL ); tp3.tv_sec = tp2.tv_sec - tp.tv_sec; tp3.tv_usec = tp2.tv_usec - tp.tv_usec; if (tp3.tv_usec < 0) { tp3.tv_sec--; tp3.tv_usec += 1000000; } fprintf( stderr, "Connection timed out after %d.%06.6d seconds, at: %s", tp3.tv_sec, tp3.tv_usec, asctime( localtime( &tp2.tv_sec ) ) ); exit(1); } <END FILE>