Tag Archives: 3 SQL SERVER learning

Error = [Microsoft][SQL Server Native Client 11.0]Unable to open BCP host data-file

Execute the BCP command today, and put the query results into an Excel file locally.
Command:
EXEC master.. Arbitrary N ‘BCP “SELECT” database ID’, ‘ ‘the name of the database “, “object ID”‘, ‘ ‘the name of the table “, “query”‘, ‘total consumption of CPU time (ms)’, ‘execution times’,’ ‘the average consumption of CPU time (ms)’, ‘ ‘ ‘ ‘the last execution time,’ minimum execution time (ms)] ‘, ‘ ‘maximum execution time (ms)’ UNION ALL SELECT CAST (dbid AS NVARCHAR(100)),dbname,CAST(ObjectId AS NVARCHAR(100)) ,ObjectName ,SelectStatement ,CAST(total_worker_time AS NVARCHAR(100)) , CAST(execution_count AS NVARCHAR(100)) ,CAST( avg_elasped_time AS NVARCHAR(100)) ,CAST( last_execution_time AS NVARCHAR(100)),CAST(min_worker_time AS NVARCHAR(100)) ,CAST( max_worker_time AS NVARCHAR(100)) FROM db.dbo.bdd_temp_find_top_select_cpu “queryout e: top_select_cpu.txt-c-s “10.0.8.102\sqlinstance” -t ‘
Error:

What went wrong:
You may not have the path or you may not have write permission for the path.
Solution: Change to a path with permissions or grant the corresponding permissions.
I chose to switch to a path with permission:
EXEC master.. Arbitrary N ‘BCP “SELECT” database ID’, ‘ ‘the name of the database “, “object ID”‘, ‘ ‘the name of the table “, “query”‘, ‘total consumption of CPU time (ms)’, ‘execution times’,’ ‘the average consumption of CPU time (ms)’, ‘ ‘ ‘ ‘the last execution time,’ minimum execution time (ms)] ‘, ‘ ‘maximum execution time (ms)’ UNION ALL SELECT CAST (dbid AS NVARCHAR(100)),dbname,CAST(ObjectId AS NVARCHAR(100)) ,ObjectName ,SelectStatement ,CAST(total_worker_time AS NVARCHAR(100)) , CAST(execution_count AS NVARCHAR(100)) ,CAST( avg_elasped_time AS NVARCHAR(100)) ,CAST( last_execution_time AS NVARCHAR(100)),CAST(min_worker_time AS NVARCHAR(100)) ,CAST( max_worker_time AS NVARCHAR(100)) FROM db.dbo.bdd_temp_find_top_select_cpu “queryout \\10.0.9.177\software\ top_select_cpu.txt-c-s “10.0.8.102\sqlinstance” -t ‘