How to create geodatabase with database string connection

203
4
2 weeks ago
sbrowneotogo
New Contributor

I'm trying to create a geodatabase in an SQL Server database after connecting to it with the CreateDatabaseConnectionString function. I get a success message running this function and save the output as connect_str. In the example script from the function documentation, they seemed to simply replace a feature layer with the connecting string object like so:

arcpy.Buffer_analysis(data_conn_str, r"c:\temp\Buffers.shp", "10 Miles")

I tried creating a GDB by providing the connection string to the CreateFileGDB function: arcpy.CreateFileGDB_management(connect_str, 'my_gdb.gdb')

I'm not supplying the entire error message because it includes server login information:

 

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: File GDB Location: Dataset CIMDATA=<CIMStandardDataConnection xsi:type='typens:CIMStandardDataConnection' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/3.1.0'><WorkspaceConnectionString>
(removed server login info here)
</WorkspaceConnectionString><WorkspaceFactory>SDE</WorkspaceFactory><DatasetType>esriDTAny</DatasetType></CIMStandardDataConnection> does not exist or is not supported Failed to execute (CreateFileGDB).

 

0 Kudos
4 Replies
BlakeTerhune
MVP Regular Contributor

CreateDatabaseConnectionString() only connects to an edbms, not a file geodatabase. Therefore, CreateFileGDB() doesn't accept a database connection string; the parameters are for an output folder and name.

I see you've also included a code snippet for Buffer. Is there something else you're trying to do?

0 Kudos
sbrowneotogo
New Contributor

I only need to do two things. It seems like it should be really simple but I'm struggling to do it.

1) Upload some tables into an SQL database

2) Users within my organization run a python toolbox that pulls data from the SQL database.

Originally I tried to do it with an SDE (my other post) but that didn't work. I tried manually connecting and uploading with pyodbc but Arcpy couldn't read the data when I uploaded it through a different process.

0 Kudos
anonymous_geographer
Occasional Contributor

So a database in SQL Server is not called a file geodatabase. It's called an enterprise geodatabase. You need to start with the correct tool and go from there (documentation).

arcpy.management.CreateEnterpriseGeodatabase()

 

sbrowneotogo
New Contributor

This seems like it's probably the right direction, though it doesn't work because apparently my SQL instance in Azure doesn't have permissions to grant the privileges to create an account and it errors out. Sigh 😞

0 Kudos