为了避免每次运行程序前都要去手动打开sqlserver和esri_sde服务,我在主对话框的Load中加入了启动进程和服务的程序。
打开进程的方法是要用到System.Diagnostics.Process
还有一种方法是新建一个.dat文件,在其中写入
net start"SQL Server(MSSQLSERVER)"
Pause
net start "esri_sde"
pause
然后用shell来启动。
ArcSDE连接的代码是:
Dim iPropertySet As New ESRI.ArcGIS.esriSystem.PropertySet Dim iSDEWorkspaceFactory As New ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactory 'On Error GoTo CheckErr With iPropertySet .SetProperty("SERVER", "") .SetProperty("INSTANCE", "") .SetProperty("USER", "") .SetProperty("PASSWORD", "") .SetProperty("VERSION", "") End With Dim pWorkspace As IWorkspace pWorkspace = iSDEWorkspaceFactory.Open(iPropertySet, 0) iPropertySet = Nothing iSDEWorkspaceFactory = Nothing Exit Sub 'CheckErr: pWorkspace = Nothing