Hi ALL,
I need to delete 1st and last lines of text from a text file in an automated process,and save the file with the same name or a different name at the same location. How is that possible?Any help is greatly appreciated.
Thanks!!
Sai.
Hi, for some AP issue, the file I upload must be without the line feed/carriage return in the last line. for example:
original fixed-length file (exported from SSIS) line NO DATA 1 AA123456 50 60 2 BB123456 30 40 3 CC123456 80 90 4 <-- with line feed/carriage return in the last line
The file format that AP request. The file only has 3 records, so it should end in the third line. line NO DATA 1 AA123456 50 60 2 BB123456 30 40 3 CC123456 80 90
Should I use script component to do it ? I am new for VB . Anyone would help me ?
Basically remove any line that start with a "#" or any blank lines..
I am assuming you can do this only using a script component and not directly through ssis..but i am not too familiar with scripting...so some code would be helpful
I am writing a string to a text file using the below code:
DECLARE @MyText nvarchar(500) SET @MyText = 'type This is my text >> c:MyLog.txt' exec master..xp_cmdshell @MyText
What I want to know is. how do I write multiple lines to MyLog.txt without having to call out xp_cmdshell each time I want a new line in my log? Do I use newline character in @MyText like SET @MyText = 'type This is my text line 1</n>This is line2 >> c:MyLog.txt'
Using ADO to conect to a text format data file to gather data. File is a .dat file, tab delimited, no header row.
Got all my ducks in a row: 1) Write a schema.ini 2) Make sure the extension is not excluded in the Jet Text registry key 3) Setup the connection properly (per MSDN Scripting help)
Works nicely, except the fist line of data is missing. File contains 78 rows of data, Jet is skipping the first line every time and reporting 77 rows.
Notes: 1) Adding a blank row, as suggested in this forum, is not an option - the data files are machine generated are not to be altered by other processes. 2) I could do it the old fashion way of importing and splitting into arrays, but this is a database function and ADO should be able to handle it.
Code samples:
Code Block
adoCON.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath & ";Extended Properties=""text;HDR=NO;FMT=Delimited;"";" On Error Resume Next rsSrc.Open "Select * From " & sFile, adoCON, adOpenStatic, adLockOptimistic, adCmdText sPath is a string containing the path, including the trailing sFile is a string containing the file name.
I've Executed DBCC CHECKDB in the T-SQL in the Query Analyser, then i got results in the Grid, but i wana to store that Information Immidiatly in the Text file, useing T-SQL Script, please help any one how to write T-SQL.
i know that going into menu-Query- Results to File. i don't want to do like that.
I want to save through writing T-SQL Script
Please help any body know.... Thanks in Advance....
created a very basic flow in SSIS: extracted table data through ole db connection, added multicast and as end result i created a flat file destination (with .txt file) and a ole db destination.
My question is; how can i delete the .txt file before executing the flow again? Want to avoid that the .txt file has duplicated rows after a second execution of the flow. Is it possible to use scd component or is this way to complicated? A for each loop?
i need a similar solution for the data that will be transported through the ole db destination task....
I have an SSIS which goes to a web hosting site and gets the store xml file, saves the file on my computer. Then I want to run a T-SQL script but if fails because the files contains DOCTYPE StoreExport SYSTEM http://store.yahoo.com/doc/dtd/StoreExport.dtd>
I want to manully remove then line before running the T-SQL script. Here is the beginning of the script:
DECLARE @x XML
SELECT @x =cast(bulkcolumn as XML)
FROM OPENROWSET(BULK 'C:databasexmldtdyahoostore.xml', SINGLE_BLOB) AS x
I thought the cast statement would get rid of the line, but it does not.
Ok so I have some dynamic sql to delete a file that is created via sql earlier on. It is to provision a copy of a database to an instance on link server. Everything works great and the files used to delete. Now, with no code changes it is throwing a syntax error. I do a print of what the dynamic sql is creating before executing and then I copy / paste what was generated into command prompt and guess what!! The file deletes.
Here is the result on screen:
@DeleteBackupFileStatement: DEL adas16.clients.advance.localwip$AvionteAP_Template_893.bak /Q Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ''. Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ''.
Here is the code that creates the statement:
SET @DeleteBackupFileStatement = NULL BEGIN SET @DeleteBackupFileStatement = 'DEL ' + LTRIM(RTRIM(@BackupFile)) + ' /Q' END PRINT '@DeleteBackupFileStatement: ' + cast(@DeleteBackupFileStatement as varchar(400)) BEGIN EXEC adasdb.master.sys.Sp_executesql @DeleteBackupFileStatement END END
The value of @BackupFile is simply the path of the file with the file name, everything in the prepared statement with the exception of DEL and the switch at the end.
I am trying to use several tables that have one 10-character text field in common. Most of the records have a numeric expression, but some tables have leading 0's, and some don't. I can't cast the field to numbers because there are some records that have letters also. What function can I use to get rid of all the 0s at the left of each record? (Sort of a LTRIM function that gets rid of 0s instead of spaces).
Hi, I have a Multiline Textbox in my application.The value from the textbox is updates in a SQL table.The problem i have is If I type in the textbox 1211 London street Sussex <br> UK <br>Europe ,only 1211 London street Sussex gets into the table.Anything I type after the "Enter " doesnot go into the table.
I checked the field sizes in my stored procedure and they are varchar(500) .
I am displaying a complex formula in a column header tool tip. The formula is generated in a stored procedure. (I do not enter the tool tip text directly in the column header expression.)
Within the stored procedure, how do I generate a string that contains a carriage return/line feed?
I want to trim new line from string in sql server 2005...
I prepared one dtsx package and in that I want to trim new line from one of my column but i am unable to do that.
for example:
I want to retrive one column name DESCRIPTION and put that in text file but along with it I am getting blank space and new line also that I want to trim...
I have to output as one filed name, mailing address, and phone of each company that we do business with. the out put must look as follows: Company Name Store number: ##### Street Address 1 Street Address 2 City, State Zip + 4 Phone: (###) ###-####
Each piece of data is a single field and will have to be concatenated into one. How do I force the line breaks where I need them?
Also each piece of data will be compared to a €śsource€? for validity and I will need to mare the individual data pieces red where €śwrong€?. Like so: VALID MY DATA Company Name Company Name Store number: ##### Store number: ##### Street Address 1 Street Address 1 Street Address 2 Street Address 2 City, State Zip + 4 City, State Zip + 4 Phone: (###) ###-#### Phone: (###) ###-####
Any ideas on how to do this? I have used IIF for conditional formating of field colors in the past, but my expierence is that it changes the WHOLE display field not just piece of data the IIF is wrapped around.
How can you delete a log file. Say I have backed up a transaction log at some drive say G:. Now I want to delete this log file and want to define it in a job. What is the syntax - delete G:Test_log.bak ???? What is a proper syntax?? Thanks!
I am trying to write a user defined function that will allow me tostrip off the last carriage return and line feed from a text field.We have address fields stored in a text field for our ERP system andsome of them have an extra carriage return and line feed at the end ofthem. This causes havoc when we sync between our ERP system and CRMsystem. If anyone knows a way to solve this problem the help would beappreciated.Examples:Existing Text field with CR:1234 Blah Street<CR>Suite 2345<CR>Corrected Text field:1234 Blah Street<CR>Suitr 2345
can some one please help me to delete a File with extension .mdf, as its continously giving error that file can't be deleted its being used by any other program or user.
I am trying to remove the transaction log file since I have created another one on a seperate drive by it wont let me do it . I get this error "cant delete the primary data or log file" Now microsoft site clearly state steps for deleting the transaction log file , by first emptying it and then deleting it BUT IT DOESNT WORK. I have even tried detaching the database and then removing the transaction log file and then attaching the database again BUT it attaches the transaction file back again GRRRRRR
then on top of this MS SQL studio does not allow to put PRIMARY or anyother value to the Filegroup for tansaction log files so how on earth can a transaction file be "primary" as the error is stating ??????
can anyone tell me how to get rid of a transaction log file that was created with the database ?
Server: Msg 1101, Level 17, State 10, Line 1 Could not allocate new page for database 'TEMPDB'. There are no more pages available in filegroup DEFAULT. Space can be created by dropping objects, adding additional files, or allowing file growth.
So went to EM & added another file (Additional file in some other drive ) to the Tempdb , now I want to delete this file ???
What are the steps ... I cant re-start the SQL Server
I can not delete this file from C/Windows/Temp directory, all other files form that foder I can delete. The error message I get is that something else is using this file. The thing is I cant find what is using it, even though I uninstaled SQL Server 2005 completely. I have tried lots of things, nothing helps. At the end I entered windows in SAFE MODE, went to Computer Management and disabled almost every service I can, that might be using it, and still cant get rid of this SQL.LOG which is 26GB now. The only thing I could do is to compress the file and now it is 6.5GB.
In SQL 2012 I'm trying to delete a log file (both physically and logically). There are two log files and one of them is unnecessary. When I click 'remove' in SSMS it will delete the log file, but then when I go back under database properties it's still showing up even though the file has been physically removed from the OS. I'm wondering what steps I can take to get rid of the file permanently?
When I delete substantial amounts of data using the SQL DELETE command, the database size apparently remains the same (702 mb) and the log file goes from about 17 mb to over 1 gig. I was expecting for the overall size to decrease drastically, but got just the opposite.
Is this typical? Can I do something to slim it down? As I am just trying to decrease the overall size to make it easier to work with when creating my application in VB, I am not worried about restoring the db (I have secure copies).
I use discountasp.net. I've added some new tables that I'd like to place on my website. My problem is that if I reattach my mdf file to my server, my member roster gets deleted. So my question is how can I update the mdf file without losing member information?
I have maually deleted the Database.LDF file by stopping the SQL Server. When i start the SQL Server, merge replication which was configured for the database does not work. How do i fix this problem.
I'm new to SQL Server 2005 (up until now I've been an Oracle DBA exclusively) and have been tasked with backing up all (6) of our SQL Server 2005 databases on a regular basis. To accomplish this, I've created individual SQL Server jobs for each database I wish to backup. Each of these jobs executes a T-SQL script like this:
BACKUP DATABASE [MYDATA] TO DISK = N'\networksharemydata.bak' WITH RETAINDAYS = 4, NOFORMAT, NOINIT, NAME = N'MyData-FullBackup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO
My goal in specifying 'RETAINDAYS = 4' was so that there would always be 4 days worth of "backupsets" (forgive my Oracle-ese) kept in mydata.bak. But when I look at the amount of backupsets kept in mydata.bak I noticed that all of them were being kept and none were being deleted.
I researched this problem a little bit and thought I had discovered a solution by specifying 'INIT' instead of 'NOINIT' and 'NOSKIP' instead of 'SKIP', but this deletes the entire contents of mydata.bak only-if all of the backupsets contained in it are past their expiration date. I was hoping it would just delete the expired backupsets and keep the non-expired ones, but this isn't the case.
Does anyone know the simplest way - with T-SQL commands - to accmplish the task of backing up a database to 1 individual .bak file and also only retain x amount of "backupsets" within it? Any help would be greatly appreciated, and the more detailed the better. Thanks.
I'm new to SQL Server 2005 (up until now I've been an Oracle DBA exclusively) and have been tasked with backing up all (6) of our SQL Server 2005 databases on a regular basis. To accomplish this, I've created individual SQL Server jobs for each database I wish to backup. Each of these jobs executes a T-SQL script like this:
BACKUP DATABASE [MYDATA] TO DISK = N'\networksharemydata.bak' WITH RETAINDAYS = 4, NOFORMAT, NOINIT, NAME = N'MyData-FullBackup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO
My goal in specifying 'RETAINDAYS = 4' was so that there would always be 4 days worth of "backupsets" (forgive my Oracle-ese) kept in mydata.bak. But when I look at the amount of backupsets kept in mydata.bak I noticed that all of them were being kept and none were being deleted.
I researched this problem a little bit and thought I had discovered a solution by specifying 'INIT' instead of 'NOINIT' and 'NOSKIP' instead of 'SKIP', but this deletes the entire contents of mydata.bak only-if all of the backupsets contained in it are past their expiration date. I was hoping it would just delete the expired backupsets and keep the non-expired ones, but this isn't the case.
Does anyone know the simplest way - with T-SQL commands - to accmplish the task of backing up a database to 1 individual .bak file and also only retain x amount of "backupsets" within it? Any help would be greatly appreciated, and the more detailed the better. Thanks.
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)