阅读:1875回复:1
用c api连接sde
HowTo: Create a connection to an ArcSDE server with the ArcSDE C API
Summary This sample C function retrieves ArcSDE connection parameters from environment variables and/or the command line. It also creates a connection to an ArcSDE server. Procedure This example first looks for specific environment variables, and uses their values for server name, instance name, database, user name and password. Next, it parses the standard C command line (passed from the caller) for the options "-s" (server name), -i (instance name), "-D" (database name), "-u" (user name) and "-p" (password). It then verifies that all necessary parameters are present. If so, it calls SE_connection_create. To use this example from your C program, call this function using the argc and argv arrays received by main(). The function fills in the variable pointed to by the 'connection' parameter with an ArcSDE connection handle. The function returns an ArcSDE standard error code, or the error code defined in ERROR_MISSING_CONNECTION_PARAMETERS, if needed parameters are missing. /* *********************************** *** *** std_connection.c *** Create an ArcSDE connection *** using environment variables *** and command line arguments *** for connection parameters. *** SAMPLE CODE *** *********************************** */ #include <stdlib.h> #include <sdetype.h> #include <sdeerno.h> #include <string.h> #define ENV_SERVER "SDESERVER" #define ENV_INSTANCE "SDEINSTANCE" #define ENV_DATABASE "SDEDATABASE" #define ENV_USERNAME "SDEUSER" #define ENV_PASSWORD "SDEPASSWORD" /* Use a numeric code that you want to return */ /* if any needed parameters are missing */ #define ERROR_MISSING_CONNECTION_PARAMETERS -5501 LONG std_connection(int argc, char **argv, SE_CONNECTION *connection, SE_ERROR *error) { LONG rc = SE_SUCCESS; char *server=(char*)NULL; char *instance=(char*)NULL; char *database=(char*)NULL; char *username=(char*)NULL; char *password=(char*)NULL; int i; *connection = (SE_CONNECTION) NULL; /* getvar will return a NULL if the environment variable does not exist */ server = getenv ( ENV_SERVER ); instance = getenv ( ENV_INSTANCE ); database = getenv ( ENV_DATABASE ); username = getenv ( ENV_USERNAME ); password = getenv ( ENV_PASSWORD ); for ( i = 0; i < (argc - 1); i++ ) { if ( strcmp("-D", argv) == 0 ) { i++; database = argv; } else if ( strcmp("-i", argv) == 0 ) { i++; instance = argv; } else if ( strcmp("-p", argv) == 0 ) { i++; password = argv; } else if ( strcmp("-s", argv) == 0 ) { i++; server = argv; } else if ( strcmp("-u", argv) == 0 ) { i++; username = argv; } } if ((!server) || (!instance) || (!username) || (!password)) { return ERROR_MISSING_CONNECTION_PARAMETERS; } rc = SE_connection_create( server, instance, database, username, password, error, connection); return rc; } |
|
1楼#
发布于:2003-08-01 12:25
为了先凑够帖子,大家别怪我:)
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶 顶顶顶 顶顶顶顶顶 顶顶顶顶顶顶 顶顶顶顶顶顶顶 顶顶顶顶 顶顶顶顶顶 顶顶顶顶顶 顶顶顶顶顶顶顶顶顶 顶顶顶顶 顶顶顶顶 顶顶顶顶 顶顶顶顶顶顶顶顶顶顶顶顶 顶 顶顶 顶顶 顶顶 顶 顶顶顶顶顶顶顶顶顶顶 顶顶顶 顶顶 顶 顶顶顶顶顶 顶顶顶顶顶顶顶顶顶 顶顶顶 顶顶顶顶 顶顶顶顶 顶顶顶顶顶顶顶顶顶顶 顶 顶 顶顶顶顶顶 顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶 顶 顶 顶顶 顶顶 顶 顶顶顶顶顶顶顶顶顶 顶顶顶顶 顶顶顶顶 顶 顶顶 顶顶顶顶顶顶顶顶 顶 顶 顶顶顶顶 顶顶顶顶顶 顶顶顶顶顶顶顶顶 顶 顶顶 顶 顶顶顶顶 顶顶顶顶 顶顶顶顶顶顶 顶顶 顶顶顶顶顶 顶顶顶顶 顶顶顶 顶顶 顶顶顶顶 顶 顶顶 顶顶 顶顶顶顶 顶 顶顶顶顶 顶顶顶顶顶 顶顶顶 顶顶顶顶 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 |
|
|