【IT168技术文档】
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);
'--------------↓声明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