proc이 openwset 함수를 사용하여 파일을 읽은 다음 bcp 명령을 사용하여 파일을 내보내는 작업입니다. 최근까지도 완벽하게 작동했습니다. 내가 작업을 실행할 때 그것은 나에게 오류를 제공합니다 : - 여기 이 오류를 해결하는 방법 SQl 서버 에이전트 작업을 실행하는 중입니까?
이 프로 시저 코드를 저장 : - 사전에NT AUTHORITY\LOCAL SERVICE. Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)". [SQLSTATE 42000] (Error 7303) Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install. [SQLSTATE 01000] (Error 15457) Configuration option 'Ad Hoc Distributed Queries' changed from 1 to 1. Run the RECONFIGURE statement to install. [SQLSTATE 01000] (Error 15457) OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "Unspecified error". [SQLSTATE 01000] (Error 7412). The step failed.
ALTER PROCEDURE [dbo].[Read_Excel]
@ExcelFilePath varchar(500)
,@OutPutFilePath nvarchar(500)
,@ServerName nvarchar(500)
,@DatabaseName nvarchar(100)
,@UserName nvarchar(50)
,@Password nvarchar(50)
,@Delimiter char(1)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Query nvarchar(1000)
DECLARE @Cmd varchar(1000)
DECLARE @FileExists int
-- Check File Existence
EXEC master..xp_fileexist @ExcelFilePath, @FileExists OUTPUT --returns 1 if exists, 0 if file is not there
if @FileExists <> 1
BEGIN PRINT 'There is no excel file available: ' + @ExcelFilePath RETURN END
-- Allow Ad hoc Distributed Queries in order to run OpenRowset Function
EXEC SP_CONFIGURE 'show advanced options', 1
RECONFIGURE
EXEC SP_CONFIGURE 'Ad Hoc Distributed Queries', 1
RECONFIGURE
-- Clear tbl_excel Table
TRUNCATE TABLE tbl_Excel
--Read EXCEL File using OPENROWSET Function
SET @Cmd = 'INSERT INTO tbl_Excel
SELECT * FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'', ''Excel 8.0;HDR=YES;IMEX=1;Database=' + @ExcelFilePath + ''',
''SELECT * FROM [Sheet1$]'')'
EXEC(@Cmd)
-- Allow Ad hoc Distributed Queries in order to run OpenRowset Function
EXEC SP_CONFIGURE 'show advanced options', 1
RECONFIGURE
EXEC SP_CONFIGURE 'Ad Hoc Distributed Queries', 0
RECONFIGURE
--Query View
SET @Query = 'SELECT id1, name1, name2, address1, address2 FROM [' + @DatabaseName + '].[dbo].[tbl_Excel]'
SET @Cmd = 'bcp "' + @Query + '" queryout "' + @OutPutFilePath +
'" -c -S' + @ServerName + ' -U' + @UserName + ' -P' +
@Password + ' -t' + @Delimiter + ''
EXEC master..xp_cmdshell @Cmd
END
감사합니다.
이 나에게 보이는 ACE 대신 사용 JET를 사용하지하려고 차 PROC에 전달하지 못한 것 ? – Widor
위도르, proc을 확인하십시오. 단서가 있다면 – User13839404
홀리 쓰레기. 방금 SQL Server 에이전트 서비스 계정을 localservice에서 NetworkService로 변경했습니다. 그리고 효과가있었습니다. – User13839404