AnsweredAssumed Answered

Create Database Connection - can't find the feature classes

Question asked by MollyKFoley on Feb 26, 2018
Latest reply on Feb 27, 2018 by MollyKFoley

EDIT: When I try to access the workspace properties of the connection file, it says that the method workspaceType doesn't exist for describing data. When I use the regular 'Database Connections\myDB.sde' connection I can access the workspace properties just fine. When I run desc.dataType on it it comes back as "File"...how do I make it a workspace? The connection file is obviously not being treated as a workspace, and that's the first issue..

 

I'm getting an exit code of 0 and no errors when I do this, but it's not finding any feature classes so it's not working as I expect it to.

 

The problem is that I'm creating a connection file using database authentication, setting the workspace to that connection file, then trying to list the feature classes. I get nothing returned. My first thought is that it's a permissions issue but the database user being used for authentication has read and write access, so now I'm not sure what the deal is. 

 

import arcpy

arcpy.CreateDatabaseConnection_management(r'C:\Users\xxx\Desktop\GIS_Testing', 'HBMTest.sde', 'SQL_SERVER',
                                          'sde:sqlserver:myServerName', 'DATABASE_AUTH', 'HBMWriter', 'xxx',
                                          'SAVE_USERNAME', 'myDBName')

arcpy.env.workspace = r'C:\Users\xxx\Desktop\GIS_Testing\HBMTest.sde'
featClasses = arcpy.ListFeatureClasses('*')
for fc in featClasses:
    print fc

 

When I use the code below, it works and will list the feature classes, but the purpose of using the "CreateDatabaseConnection" and passing in credentials is because eventually this script will be published up on a server where external users will be running it and they won't have my windows authentication to access the database, so I really need to make sure that the above is working.

 

arcpy.env.workspace = r'Database Connections\HBMTest.sde'
featClasses = arcpy.ListFeatureClasses('*')
for fc in featClasses:
  print fc

 

Am I missing some silly thing in arcpy or is this more likely a permissions issue? These are the permissions set in SQL Server Mgmt Studio for the user:

Outcomes