gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:1875回复:1

用c api连接sde

楼主#
更多 发布于:2003-07-29 22:20
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;
}
喜欢0 评分0
狐兄
路人甲
路人甲
  • 注册日期2003-07-28
  • 发帖数62
  • QQ67586473
  • 铜币280枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2003-08-01 12:25
为了先凑够帖子,大家别怪我:)

顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
 顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶顶 顶顶顶  顶顶顶顶顶
 顶顶顶顶顶顶    顶顶顶顶顶顶顶 顶顶顶顶 顶顶顶顶顶
 顶顶顶顶顶   顶顶顶顶顶顶顶顶顶 顶顶顶顶  顶顶顶顶
 顶顶顶顶  顶顶顶顶顶顶顶顶顶顶顶顶 顶   顶顶 顶顶
 顶顶  顶 顶顶顶顶顶顶顶顶顶顶  顶顶顶 顶顶   顶
 顶顶顶顶顶 顶顶顶顶顶顶顶顶顶   顶顶顶   顶顶顶顶
 顶顶顶顶   顶顶顶顶顶顶顶顶顶顶 顶  顶 顶顶顶顶顶
 顶顶顶顶顶顶顶 顶顶顶顶顶顶顶顶顶  顶  顶   顶顶
 顶顶   顶  顶顶顶顶顶顶顶顶顶 顶顶顶顶  顶顶顶顶
 顶 顶顶   顶顶顶顶顶顶顶顶   顶   顶 顶顶顶顶
 顶顶顶顶顶  顶顶顶顶顶顶顶顶 顶  顶顶 顶 顶顶顶顶
 顶顶顶顶    顶顶顶顶顶顶 顶顶 顶顶顶顶顶 顶顶顶顶
 顶顶顶  顶顶   顶顶顶顶 顶  顶顶 顶顶 顶顶顶顶
 顶   顶顶顶顶    顶顶顶顶顶 顶顶顶   顶顶顶顶
 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶
天下英雄出我辈 一入江湖岁月催; 宏图霸业谈笑中 不胜人生一场醉; 提剑跨骑挥尾雨 白骨如山鸟惊飞; 尘世如朝人如水 只叹江湖几人回;
举报 回复(0) 喜欢(0)     评分
游客

返回顶部