zoukankan
html css js c++ java
ArcSDE C API在.NET中的调用
在.NET中调用API函数
C#:
using
System.Runtime.InteropServices;
[DllImport(
"
sde.dll
"
)]
//
还有其他的属性可参考MSDN
public
static
extern
Int32 SE_connection_create(
string
server,
string
instance,
string
database,
string
username,
string
pwd,
ref
SE_ERROR error,
out
IntPtr pSdeConn);
VB.NET:
Imports
System.Runtime.InteropServices
<
DllImport(
"
sde.dll
"
, SetLastError:
=
True
, ThrowOnUnmappableChar:
=
True
)
>
_
Public
Shared
Function SE_connection_create()
Function
SE_connection_create(
ByVal
server
As
String
,
ByVal
instance
As
String
,
ByVal
database
As
String
,
ByVal
username
As
String
,
ByVal
password
As
String
,
ByRef
error1
As
SE_ERROR,
ByRef
connection
As
IntPtr)
As
Int32
End Function
还可以使用Declar关键字来引用API函数,这里就不介绍了。
ArcSDE C API的声明方法
'--------------↓声明SE_ERROR结构体↓-----------------
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure SE_ERROR
Public sde_error As Int32
Public ext_error As Int32
'<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512)> _
Public err_msg1 As Char()
'<MarshalAs(UnmanagedType.ByValArray, SizeConst:=4096)> _
Public err_msg2 As Char()
End Structure
'--------------↑声明SE_ERROR结构体↑-----------------
'-------------------调用SE_connection_create函数----------------------
'------------------连接SDE-------------------------
'返回结果
'SE_SUCCESS 0
'SE_FAILURE -1
'SE_NO_ACCESS -15
'SE_SDE_NOT_STARTED -5
'SE_IOMGR_NOT_AVAILABLE -101
'SE_INVALID_DATABASE -162
'SE_INVALID_SERVER -100
'SE_INVALID_POINTER -65
'SE_INVALID_USER -9
'SE_LOGIN_NOT_ALLOWED -8
'SE_DBMS_DOES_NOT_SUPPORT -1008
'SE_NET_FAILURE -10
'SE_NET_TIMEOUT -11
'SE_SERVICE_NOT_FOUND -102
'SE_TASKS_EXCEEDED -7
<DllImport("sde.dll", SetLastError:=True,ThrowOnUnmappableChar:=True)> _
Public Shared Function SE_connection_create(ByVal server As String, ByVal instance As String, _
ByVal database As String, ByVal username As String, ByVal password As String, ByRef error1 As SE_ERROR, _
ByRef connection As IntPtr) As Int32
End Function
'----------------------------调用SE_connection_free函数-------------------------
'----------------------------释放SDE连接----------------------
<DllImport("sde.dll", SetLastError:=True, ThrowOnUnmappableChar:=True)> _
Public Shared Sub SE_connection_free(ByVal Byrefconnection As IntPtr)
End Sub
在程序中的调用
Imports QHProject.SDE_C_API
Imports System.Runtime.InteropServices
Partial Class MapServicePage
Inherits System.Web.UI.Page
Private Shared conn As IntPtr = Nothing
Private error1 As QHProject.SDE_C_API.SDE_C_API_Operation.SE_ERROR = Nothing
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Int32 = SDE_C_API_Operation.SE_connection_create("CL", "5151", "sde", "sde", "clbeyond", error1, conn)
Button1.Text = i.ToString()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
SDE_C_API_Operation.SE_connection_free(conn)
End Sub
End Class
连接成功后Button的Text属性会显示为0,表示连接成功,在任务管理器中就会发现出现了一个gsrvr.ext进程。断开连接后gsrvr.exe进程就会消失。
当然前提是要在程序中将连接字段conn声明为shared类型(C#中的Static类型)。
需要注意的是Instance不是"esri_sde",而是端口号,一般为5151。
2008年3月10日15:41:31
查看全文
相关阅读:
Fortify Audit Workbench Cookie Security: Cookie not Sent Over SSL
Fortify Audit Workbench 笔记 Access Control: Database
MATLAB中的polyfit函数的使用方法
编写python代码时出现SyntaxError: invalid character in identifier的解决方法
Windows10安装MinGW-W64出现Cannot download repository.txt的一种解决方法
使用IDM下载B站视频出现声音跟视频分离的一种解决方法
简洁桌面(使用Windows自带的桌面整理功能)
MATLAB标记图像中特殊的点
解决python使用pip安装下载库出现错误:ERROR:Cannot unpack file xxxx情况
解决python使用pip下载安装库速度慢问题
原文地址:https://www.cnblogs.com/danni5678/p/1098854.html
最新文章
数据库的隔离级别
个人对单例模式的理解
大四第一次找实习工作经历的笔试面试题合集
初次使用SpringBoot内嵌服务器以jar包方式运行web工程遇到的坑
模仿LinkedList和它的Iterator
模仿ArrayList和它的Iterator
IDEA maven java项目导包失败的坑
fastdfs的搭建和配置
Java集合写的通讯录
个人对Java中super关键字的理解
热门文章
vue多个项目公共化组件方案
Nginx部署vue项目
Fortify Audit Workbench 笔记 Password Management: Password in Configuration File(明文存储密码)
Fortify Audit Workbench 笔记 Command Injection(命令注入)
Fortify Audit Workbench 笔记 Unreleased Resource: Database( 未释放资源:数据库)
Fortify Audit Workbench 笔记 SQL Injection SQL注入
Fortify Audit Workbench 笔记 Path Manipulation
Fortify Audit Workbench 笔记 Header Manipulation
Fortify Audit Workbench 笔记 Dynamic Code Evaluation: Code Injection
Fortify Audit Workbench 笔记 Cross-Site Scripting-Persistent
Copyright © 2011-2022 走看看