Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem using sp_OACreate to create a text file in SQL server 2005

Posted on 2008-10-01
4
Medium Priority
?
686 Views
Last Modified: 2009-01-05
I am using the below code to create a log file at remote machine in SQL server 2005.

I am able to create a file successfully using the same code on SQL server 2000 but the file is not getting created in SQL server 2005.
ALTER PROCEDURE GEGR_SPODA_SHIP_RECV_temp  @param1 varchar(10) = 'DEV'									                  
AS
declare
@vchrFile VARCHAR(1000) ,
	@lv_string Varchar(8000),
	@CmdTxt Varchar(8000),
	@vchrText Varchar(8000),
        @vchrFileID INT ,
 	@FS INT ,
 	@RC INT ,
	@DBID Int,
        @DBNAME VarChar(128)
 
SELECT @vchrFile = 'C:\cmmsdevdata\Log\Temp.txt'
EXECUTE @RC = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
EXEC @RC = sp_OAMethod @FS , 'OpenTextFile' , @vchrFileID OUT , @vchrFile , 8 , -1
set @vchrText ='Text'
EXEC @RC = sp_OAMethod @vchrFileID, 'WriteLine', Null , @vchrText
EXECUTE @RC = sp_OADestroy @vchrFileID
EXECUTE @RC = sp_OADestroy @FS 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
 
 
Can someone help me with this.

Open in new window

0
Comment
Question by:kavya_deepthi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 22613037
When procedure runs the file path must be from the point of view of the SQL2005 instance, maybe that's diffrent between your SQL2000 and SQL2005.
Also the credentials to write could be diffrent, so it could be possible it runs when you start the procedure in a query window with your credentials and it fails when it runs with the credentials of SQL*Agent.
0
 

Author Comment

by:kavya_deepthi
ID: 22613218
When i am creating the file on SQL server2005..i am giving a different path accordingly.So that should not be the problem
0
 
LVL 25

Accepted Solution

by:
jogos earned 2000 total points
ID: 22613379
The second part of my comment is about credentials, follow the link for an example of what could be the problem.  SQL2005 on diffrent server? Other default-settings sql-instance as the actual in 2000 instance. Other 'User' which owns the process that runs....

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_22479836.html

Mostly when something doesn't work there is some error-message. Not always automaticly (ex SQL*Agent job -> option to log in eventvwr or to put output jobstep in a logfile.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question