Question

Passing SQL Connection parameters to cmd prompt using Python

  • 26 May 2020
  • 1 reply
  • 5 views

Hello FME People,

I am in the process of creating a workspace that reads data from geopackage and writes to SQL Server database, after performing a few transformations and checks.

I am using Python to perform pre-population of some tables in SQL Server (otherwise FME wouldn't be able to write the new tables due to schema restrictions).

At the end of the Python script I run the following statement that calls FME:

 

os.chdir("Z:\\CurrentProjects\\school-uplift\\fme")
os.system("""fme.exe geopackage2mssql_spatial.fmw"
              --DestDataset_MSSQL_SPATIAL_8 "SCHOOL_NAME"
              --SourceDataset_GEOPACKAGE_12 "..\\gpkg\\Service component type.gpkg"
              --SourceDataset_GEOPACKAGE_10 "..\\gpkg\\Service component link.gpkg"
              --DestDataset_MSSQL_SPATIAL_12 "SCHOOL_NAME"
              --FEATURE_TYPES_2 "ls_carp ls_contours ls_gate ls_landscaping ls_road ls_tree ls_bollard ls_embankment ls_fnce ls_gden ls_path ls_pond ls_steps ls_wall"
              --SourceDataset_OGCGEOPACKAGE """"""..\\gpkg\\\\buildings.gpkg"" ""{0}\\site.gpkg""""""
              --SourceDataset_OGCGEOPACKAGE_13 "..\\gpkg\\buildings.gpkg"
              --SourceDataset_OGCGEOPACKAGE_11 "..\\gpkg\\site.gpkg"
              --SourceDataset_OGCGEOPACKAGE_15 "..\\gpkg\\rooms.gpkg"
              --SourceDataset_OGCGEOPACKAGE_12 """"""..\\gpkg\\service_line_data.gpkg"" ""..\\gpkg\\service_point_data.gpkg""""""
              --SourceDataset_OGCGEOPACKAGE_14 "..\\gpkg\\floors.gpkg"
              --SourceDataset_OGCGEOPACKAGE_8 "..\\gpkg\\ls_*.gpkg""")

 

The problem I am having is that we have many schools having different SCHOOL_NAME as database connection.

I am trying to pass to the command above the database connection parameters like server name, database name, username, password... 

If that is possible, it would become more flexible to read any data and write any data for any school.

Please let me know.

 

Thanks and regards,

Gianluca

 


1 reply

Userlevel 4
Badge +26

You can switch out your database connection for an Embedded Connection instead. This should allow you to pass the connection details as host, db_name, db_pass, db_user, db_port etc.

 

 

We embed connection parameters all the time. While db connections are nice, sometimes it's just an extra layer to work through.

 

 

Reply