5

I am trying to make a connection to a SQL Server database with SdeWorkspaceFactory. This is from my Windows 7 x64 Desktop to a Network database.

If I use this:

SDEWorkspace = NewObj(esriDataSourcesGDB.SdeWorkspaceFactory, esriGeodatabase.IWorkspaceFactory2)
connectionString = "server=SQLServer;" + \
                    "instance=hbffcacqsql01;" + \
                    "database=ACQ_HBED_PROD;" + \
                    "authentication_mode=OSA"

result = SDEWorkspace.OpenFromString(connectionString, 0)

or this:

connectionProperties = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet)
connectionProperties.SetProperty("SERVER", "SQLServer")
connectionProperties.SetProperty("INSTANCE", "hbffcacqsql01")
connectionProperties.SetProperty("DATABASE", "ACQ_HBED_PROD")
connectionProperties.SetProperty("AUTHENTICATION_MODE", "OSA")

SDEWorkspace = NewObj(esriDataSourcesGDB.SdeWorkspaceFactory, esriGeodatabase.IWorkspaceFactory2)

result = SDEWorkspace.Open(connectionProperties, 0)

I get this error:

Traceback (most recent call last):
  File "C:/Users/tstanley/Downloads/ArcMap_Python/FirstTry.py", line 88, in <module>
    result = SDEWorkspace.OpenFromString(connectionString, 0)
_ctypes.COMError: (-2147216021, None, (u'Entry for SDE instance not found in services file', u'esriDataSourcesGDB.SqlWorkspace.1', u'esri_csGeoDatabase.hlp', 0, None))

If I leave out the instance parameter, the connection window pops up and if I put the same value into the window, I get a connection.

enter image description here

Can someone tell me what I'm missing?

I have read a bunch of other posts of people with this error and they mention replacing the instance with a service number, 5151. It seems that they are trying to connect to an SDE database, which this isn't. I'm really new to ArcObjects so I have just about everything still to learn.

  • 1
    The openFromString method uses the old syntax, so you've got the parameters wrong. – Vince Jul 11 '14 at 19:36
  • I added another method I tried. I think this is the syntax suggested in the ArcObjects API Reference for 10.1, resources.arcgis.com/en/help/arcobjects-net/componenthelp/… – cndnflyr Jul 11 '14 at 19:42
  • 6
    So follow the instructions of that link -- "SERVER" – SDE server name you are connecting to. "INSTANCE" – Instance you are connection to. These are not correct. Try "INSTANCE=sde:sqlserver:hbffcacqsql01" (SERVER is ignored with Direct Connect) – Vince Jul 11 '14 at 19:47
  • Ha! You're beautiful! It worked. I've run into not understanding database connection strings before. "What info goes where?" Do you have a recomendation on where to go to brush up on this? Many thanks! – cndnflyr Jul 11 '14 at 19:53
  • 1
    What suggested by Vince is direct connect method as ESRI mentioned in ArcSDE documenation.It's a good method when you want to bypass SDE service and have fat clients.All sde libraries run on client.if you still want use SDE service,using propertyset is the easiest.but you must get sure your sde service is running and there is an entry for sde service in Windows/System32/drivers/etc/services in Windows on SDE runner machine.sometimes,depending on machine configuration,sde service doesn't act properly(even it's running) if there is no any entry for it in this file. – Reza Jul 13 '14 at 5:40
4

This answer was submitted by @Vince in the comments to the initial question.

In a direct connection the Instance parameter needs to look like this

INSTANCE = sde:sqlserver:(servername)

and the Server parameter is ignored.

More information can be found here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.