Hi everybody,
I'm working with a SQL Server 2000 Database and I need to write a procedure that creates a file .log in which it has to write some potential errors occurred in other procedures.
I'm quite totally newbie to T-SQL language and its procedures, so I don't know which procedure or function creates and closes the file and which one writes something in it.
I have used the copy database wizard, but I realized I had forgotten to shrink the transaction log file. So I canceled the wizard. My database, detached by the wizard, has now disappeared. The mdf file is still there, but when I try to attach it manually I get the "create file encountered operating system error 5 while attempting to open the physical file..." error.
This is a problem I encountered when I had to detach a database file (type .mdf):
1) I went to the MS SQL Management Server Studi and detached my database file successfully from a connection called Workhorse.
2) I needed to place the .mdf database file into a zip file in order to put it on a remote server. I did this using Shared Portal. This was also successful
3) However when I tried reattaching the database file, I got this error:
CREATE FILE encountered operating system error 5A(Access denied.) while attempting to open or create the physical file "CProgram FilesMSSQL ServerMSSQLData<databasename>.mdf'
Q) The database file and log file (ldf) exist in the correct directory so I don't know what happened. Can any one help?
Hi, I want to create a text file and write to text it by calling its assembly from Stored Procedure. Full Detail is given below
I write a code in class to create a text file and write text in it. 1) I creat a class in Visual Basic.Net 2005, whose code is given below: Imports System Imports System.IO Imports Microsoft.VisualBasic Imports System.Diagnostics Public Class WLog Public Shared Sub LogToTextFile(ByVal LogName As String, ByVal newMessage As String) Dim w As StreamWriter = File.AppendText(LogName) LogIt(newMessage, w) w.Close() End Sub Public Shared Sub LogIt(ByVal logMessage As String, ByVal wr As StreamWriter) wr.Write(ControlChars.CrLf & "Log Entry:") wr.WriteLine("(0) {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()) wr.WriteLine(" :") wr.WriteLine(" :{0}", logMessage) wr.WriteLine("---------------------------") wr.Flush() End Sub Public Shared Sub LotToEventLog(ByVal errorMessage As String) Dim log As System.Diagnostics.EventLog = New System.Diagnostics.EventLog log.Source = "My Application" log.WriteEntry(errorMessage) End Sub End Class
2) Make & register its assembly, in SQL Server 2005. 3)Create Stored Procedure as given below:
CREATE PROCEDURE dbo.SP_LogTextFile ( @LogName nvarchar(255), @NewMessage nvarchar(255) ) AS EXTERNAL NAME [asmLog].[WriteLog.WLog].[LogToTextFile]
4) When i execute this stored procedure as Execute SP_LogTextFile 'C:Test.txt','Message1'
5) Then i got the following error Msg 6522, Level 16, State 1, Procedure SP_LogTextFile, Line 0 A .NET Framework error occurred during execution of user defined routine or aggregate 'SP_LogTextFile': System.UnauthorizedAccessException: Access to the path 'C:Test.txt' is denied. System.UnauthorizedAccessException: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, ileOptions options) at System.IO.StreamWriter.CreateFile(String path, Boolean append) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean append) at System.IO.File.AppendText(String path) at WriteLog.WLog.LogToTextFile(String LogName, String newMessage)
1. Flat File Source 2. Conditional Split, Case Good = !ISNULL(KEY) Case Error = ISNULL(KEY) 3. Case Good -> Writes to Good Flat File (with timestamp in the title) 4. Case Error -> Writes to Error Flat File (with timestamp in the title)
Most job runs have no errors but the error file is created as a zero byte file anyway. If there are no error records I don't want the error file created. How might I accomplish this?
I have an File System Task that copies a file from one directory ot another. When I hard code the target directory (c:dirfile.txt) it works fine. When I change it to a virtual directory (\serverdirfile.txt) I get a security error:
[File System Task] Error: An error occurred with the following error message: "Access to the path '\gracehbtest oS2TMM_Live_Title_000002.xml' is denied.".
I have a text file which needs to be created into a table (let's call it DataFile table). For now I'm just doing the manual DTS to import the txt into SQL server to create the table, which works. But here's my problem....
I need to extract data from DataFile table, here's my query:
select * from dbo.DataFile where DF_SC_Case_Nbr not like '0000%';
Then I need to create a new table for the extracted data, let's call it ExtractedDataFile. But I don't know how to create a new table and insert the data I selected above into the new one.
Also, can the extraction and the creation of new table be done in just one stored procedure? or is there any other way of doing all this (including the importation of the text file)?
hey guys, i have the job of transfering a mature database to a new server. i have done this before with the import/export utility with ease before. but this hosting company only allows import with .sql files. on my import/export program there is no .sql export option. does anyone have any ideas? i want to export the table designs and the content.
hi i have to export some databases to a xls File with DTS and VBA on a MIcrosoft SQL Server 2000. in Dts it is not very difficult but i have to do this dynamicly. So i have to create a new xls File with Scripting FileSystemObject but on the server is no Excel Application. u know how i can do this? i have mayby a solution: 1.archiving the data static 2.copy the file to other folder 3.rename the new file but then i have to delete the value of the static file before a job, otherwise the file will be bigger and bigger. any ideas? thx
i am using c# asp.net with sqlserver. so i a m inserting values from front end to back end. my need is i have to create logfile at which time i inserted,in which table i inserted,who is inserted and which operation performed.so these things i have to maintain in log file. this is my need.
actually i tried this by the following way:
i created the table log: which cotains the following field. name,desc,tablename,date
then i created one stored procedure :code:
CREATE PROCEDURE splog
(@name varchar(50), @desc varchar(50), @tabname varchar(50), @date datetime ) As begin
insert into log values ( @name,@desc,@tabname,getdate() ) end GO
then i created stored procedure for insert as follows:
CREATE PROCEDURE spemp1insert (@name varchar(50), @age int, @id int ) As begin
insert into emp1 values(@name,@id,@age)
if(@@error=0) begin execute splog @name='karthikeyan',@desc='insertoperation',@tabname='emp1' end end GO
but if i inserted my record from c#asp.net to sqlserver the record getting inseretd,but in the log table the is is no value.
so please tel me what problem i did,please help me to do this,please
So we have this database in SQL 2005, and we want to create a SQL Mobile database filled with a subset of data from that SQL 2005 database.
Replication is NOT an option for us (otherwise, believe me, we would be down that road in a heartbeat). Hence why we're trying to create the files manually.
Now, I know I could write an app that creates the .SDF file, gets the data from the master and puts it in the mobile one...but if there's a way to do it using the SQL manager or the BI development studio, I'd rather do it that way.
hi In my application i want to create a TestDB using script method. I want to send it to the client through( Websetup Project). So i need to send the exe for that TestDB.sql. I have created the TestDB.sql ( using script method). Now i need to chnage that TestDB.sql into an exe file...( SQL SERVER 2005 ) Client can click the exe. It should execute the scrpts and automatically create the database( TestDB) in client machine. can you any light on this issue for me.. thanks in advance Prabakar
hi all! i am sorry about this question but i am new to sql server.i installed sql server 2005 developer edition but there are only a few configuration tools on my computer.i used to use access but i dont know how to create a sql database file?did i install a wrong type of sql server??if not why i cant find a way to create this database??pls help meeeee!!!!!
I was running a Evaluation copy of SQL 7 and suddenly it expired. I couldn't start the SQL service any more therefore I couldn't make a backup of my database. Now I installed new SQL 7 server and my database file (xx.mdf and xx.ldf) are there. Is there a way that I can recover my databases from those files?
I have a stored procedure. This proc returns some data that needs to be put in an excel format. Is it possible to create a excel file to have the result of a select statement from the database?
this is the worst noob question ever but Google isn't helping and I searched all the threads in this forum...no help. I have a comma delimited csv file that i need to load into an existing database on MS SQL 2000. I need to know how to create the table and populate it with my data...Any pointers of the differences between syntax Of MSSQL and MySql or a tutorial of how to do it with enterprise manager would be great...Dang I feel noobie.
I'm looking for a simple way to create a text file inside a stored procedure. I want to set it up so the end user would just execute the SPROC that would run the required queries and dump the result into a custom formated text file.
I tried BCP but could not lauch it inside the SPROC without using OSQL. I am running SQL Server 2003 64bit. Any ideas?
I want to do a SQL sentence that saves the results from the select in a .txt file. I get the results as a long list on the screen, and it repeats the headers several times, so it takes quite some time to copy the results out of there. It would be better if the result was put as a list directly in to a text file.
Is there a way to create a text file (such as a Windows Notepad file)by using a trigger on a table? What I want to do is to send a row ofinformation to a table where the table: tblFileData has only onecolumn: txtOutputI want to use the DB front end (MS Access) to send the text string tothe SQL backend, then have the SQL Server create a file to a path,such as F:/myfiledate.txt that holds the text in txtOutput, then thetrigger deletes the row in tblFileData.Can this be done easily?Any help is appreciated
I need to create a CSV file by reading a table data , Can any one know how i can do this using SSIS .
My Requirment is that -
I have a temp table in which i inserted all the incorrect data during the load of a flat file using SSIS. Now i need to write all the incorrect data of the temp table in a CSV . Is there is a way i can do this using SSIS , Please help as i am new to SSIS.
I have a report that is exported to a PDF file... Is possible to get an index in the beginning of the file?? I have the page number at the bottom of each page but i would need an index...
I'm using MS Visual C# 2005 Express, but I can't create a new local database file in the "Add -> New Item" dialog. The Studio doesn't create the database, but shows a file not found message.