PT-Excel demo

Материал из archestra.info
Версия от 11:40, 19 мая 2021; Vladimir Bazhin (обсуждение | вклад) (Возможные ошибки и проблемы)

Перейти к: навигация, поиск

Ниже описан пример работы с Excel файлом из шаблона: Файл:PlanetTogether Excel Import Template 08212020.zip

Подготовка к работе с Excel

  • In order to query excel from SQL you'll need to perform the following 3 steps... Выполнить следующие шаги
  • Step1: Install 64-bit Microsoft.ACE.OLEDB.12.0 driver. Установить драйвер
  • Step2: Configure ACE OLE properties. Выполнить скрипт ниже
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
  • Step3: Configure DB properties. Выполнить скрипт ниже
EXEC sp_configure 'show advanced options', 1;  
RECONFIGURE;
GO 
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;  
RECONFIGURE;  
GO
  • Step4: Set SQL Server Windows Service Login as Local Account. Запустить службу SQL Server под локальным аккаунтом

Stored Procedures

pt_import_procedures

  • Получает имя Excel файла (@FilePath) для обработки и вызывает:
  1. dbo.get_excel_data @FilePath
  2. dbo.build_pt_tables

get_excel_data

Из листов Excel получает данные и заносит их с таблицы

  • Старые данные при этом из таблиц теряются, т.к. перед занесением выполняется drop table
  • Имена листов Excel нельзя менять
  • Лог работы процедуры ведется в таблице _log_get_excel_data
  • Создает следующие таблицы:
    • data_Plants
    • data_Resources
    • data_ResourceProductRules
    • data_Items
    • data_Routings
    • data_BOMs
    • data_RoutingAttributes
    • data_AttributeSetupMatrix
    • data_AttributeRanges
    • data_SalesOrders
    • data_PurchaseOrders
    • data_ForecastOrders
    • data_WorkOrderHeader
    • data_WorkOrderRoutings
    • data_WorkOrderBOMs
    • data_WorkOrderActivityUpdates

build_pt_tables

Из таблиц куда импортированы даныые из Excel получает данные и заносит их с таблицы для работы PlanetTogether

  • Старые данные при этом из таблиц теряются, т.к. перед занесением выполняется drop table
  • Лог работы процедуры ведется в таблице _log_build_pt_tables
  • Создает следующие таблицы:
    • pt_resources
    • pt_items
    • pt_routing_header
    • pt_routing_operations
    • pt_routing_activities
    • pt_routing_resource_requirements
    • pt_routing_required_capabilities
    • pt_routing_paths
    • pt_routing_products
    • pt_routing_bom
    • pt_routing_attributes
    • pt_attribute_setup_matrix
    • pt_attribute_ranges
    • pt_product_rules
    • pt_sales_orders
    • pt_purchase_orders
    • pt_forecasts
    • data_WorkOrdersGenerated, создается из [dbo].[build_data_workorders_generated]
    • pt_workorder_gen_header
    • pt_workorder_gen_operations
    • pt_workorder_gen_activities
    • pt_workorder_gen_resource_requirements
    • pt_workorder_gen_required_capabilities
    • pt_workorder_gen_paths
    • pt_workorder_gen_products
    • pt_workorder_gen_bom
    • pt_workorder_gen_attributes
    • pt_workorder_gen_successors
    • pt_workorder_excel_header
    • pt_workorder_excel_operations
    • pt_workorder_excel_activities
    • pt_workorder_excel_resource_requirements
    • pt_workorder_excel_required_capabilities
    • pt_workorder_excel_paths
    • pt_workorder_excel_products
    • pt_workorder_excel_bom
    • pt_workorder_excel_attributes
    • pt_workorder_excel_successors
    • pt_all_headers
    • pt_all_operations
    • pt_all_activities
    • pt_all_resource_requirements
    • pt_all_required_capabilities
    • pt_all_paths
    • pt_all_products
    • pt_all_bom
    • pt_all_attributes
    • pt_all_successors

Скачать шаблон

Файл:PlanetTogether Excel Import Template 08212020.zip

Возможные ошибки и проблемы

  • ERROR 2850:

Error running pre-import SQL 'EXEC pt_import_procedures @FilePath = 'D:\PlanetTogether\Template_Demo.xlsx. SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online. SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online. Cannot find the object "dbo.data_Resources" because it does not exist or you do not have permissions. SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.

    • Выполнить скрипт
EXEC sp_configure 'show advanced options', 1;  
RECONFIGURE;
GO 
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;  
RECONFIGURE;  
GO
  • ERROR 2850:

Error running pre-import SQL 'EXEC pt_import_procedures @FilePath = 'D:\PlanetTogether\Template_Demo.xlsx. The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider did not give any information about the error. Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

    • Выполнить скрипт
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO