Hi,
Im trying to "use" files during my flow in two diferent kind of components (send email task and custom transformation), but the error i get is similar: access denied, file doesnt exists, is locked by another proccess or not enough rigths.
-In custom transofrmation i am trying to write to a file with the next code:
Dim sw As StreamWriter
If (Not File.Exists(".\test.txt")) Then
sw = File.CreateText(".\test.txt")
Else
sw = File.AppendText(".\test.txt")
End If
sw.Write("Numero de Registros en Empresas")
sw.WriteLine(Row.CuentaRegEmpresas)
sw.Write("Numero de Registros en Reporta")
sw.WriteLine(Row.CuentaRegReporta)
sw.Write("Numero de Registros de Facturas ampliadas")
sw.WriteLine(Row.CuentaRegFAmp)
sw.WriteLine()
- In send email tranformation i am trying to attach a different file (the log of the process) , but the error is that i dont have rights to access. If i try to send another file this error disappears...
Both files (test.txt and log.txt) have total control rights to all users, and arent locked or opened by any other process during the execution.
Edit: Thats the error trace i get:
en System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
en 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)
en System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
en System.IO.StreamWriter.CreateFile(String path, Boolean append)
en System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
en System.IO.StreamWriter..ctor(String path, Boolean append)
en System.IO.File.AppendText(String path)
en ScriptComponent_14cd101f436a42b18dc68087869033b2.ScriptMain.Entrada0_ProcessInputRow(Entrada0Buffer Row)
en ScriptComponent_14cd101f436a42b18dc68087869033b2.UserComponent.Entrada0_ProcessInput(Entrada0Buffer Buffer)
en ScriptComponent_14cd101f436a42b18dc68087869033b2.UserComponent.ProcessInput(Int32 InputID, PipelineBuffer Buffer)
en Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)
You mention three different errors, can you be clear about which error happens when? Please post the exact error message as well.
Can you also explain more about the tasks, and the order they are executed within your package.
The code snippet above seems incomplete, and also rather strang, perhaps if you posted the full code it would make more sense. Based on what you have posted I'd say it is wrong, as opening the file for each row is a bad idea, and you do not close the file.
As an aside the syntax seems complicated, to append to a file, just use the constructor overload -
Code Snippet
StreamWriter stream = new StreamWriter("C:\Test.txt", true);
stream.WriteLine("Test");
stream.Close();
|||
Hi Darren,
Your are right, the problem of the custom transformation was that i did not close the StreamWriter, now it's working fine.
The other problem is that, at the end of the process i want to send the log file, but it seems like the process locks the file and cant be attached in the email... am i wrong? i will try to send the email in other package inside the same project... Its possible to send parameters to the new package?
Any other idea to send the log via email just at the end of the process?
Thanks
Edit: I have proved this solution and it doesnt work... log file cant be send using a different package inside the project.
|||Why is the file locked? If you are in control of writing the file, then you should have closed and therefore released all locks to the file, so the file should be available to send. You must have something open still. Ultimately you can use something like Process Moniotor of File? (I forget to find who has the lock), the old SysInternals tools, now MS.|||The file that is locked is the log of the process... i have read in other post that is not possible to send it becuase the own process locks it, so i decide to send via email only the errors stored in @.[System::ErrorDescription]
variable when an error event is raised.
thanks