I got my custom assembly working fine until I add writing to a log
file. Then I get a FileIOPermission error.
I have the following code in my policy file:
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ReportHelperFilePermissionSet"
Description="A special permission set that grants read access to my
currency rates file.">
<IPermission
class="FileIOPermission"
version="1"
All="C:\ReportHelper.log"/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution, Assertion"/>
</PermissionSet>
<CodeGroup class="UnionCodeGroup"
version="1"
PermissionSetName="ReportHelperFilePermissionSet"
Name="MyNewCodeGroup"
Description="A special code group for my custom assembly.">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
Services\ReportServer\bin\ReportHelper.dll"/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="AWCLibrary">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
Services\ReportServer\bin\ReportHelper.dll"/>
</CodeGroup>
I write to my log file as follows:
public static void WriteLogFile(String msg)
{
FileIOPermission perm1 = new
FileIOPermission(FileIOPermissionAccess.Write, @."C:\ReportHelper.log");
perm1.Assert();
//try
//{
FileStream fs = new FileStream(@."C:\ReportHelper.log",
FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter w = new StreamWriter(fs);
w.BaseStream.Seek(0, SeekOrigin.End);
w.Write("{0} {1} ", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());
w.Write(msg + "\r\n");
w.Flush();
w.Close();
}
What am I missing here? Any help would be appreciated.
Thanks!Check this
http://www.c-sharpcorner.com/Code/2005/June/CustomAssemblyinRS.asp
HTH
If still you face the issue, let me know (bkkrishnan [at] hotmail [dot] com)
Thanks
Balaji
Siwy wrote:
>I got my custom assembly working fine until I add writing to a log
>file. Then I get a FileIOPermission error.
>I have the following code in my policy file:
><PermissionSet
> class="NamedPermissionSet"
> version="1"
> Name="ReportHelperFilePermissionSet"
> Description="A special permission set that grants read access to my
>currency rates file.">
> <IPermission
> class="FileIOPermission"
> version="1"
> All="C:\ReportHelper.log"/>
> <IPermission
> class="SecurityPermission"
> version="1"
> Flags="Execution, Assertion"/>
></PermissionSet>
><CodeGroup class="UnionCodeGroup"
> version="1"
> PermissionSetName="ReportHelperFilePermissionSet"
> Name="MyNewCodeGroup"
> Description="A special code group for my custom assembly.">
> <IMembershipCondition
> class="UrlMembershipCondition"
> version="1"
> Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
>Services\ReportServer\bin\ReportHelper.dll"/>
></CodeGroup>
><CodeGroup
> class="UnionCodeGroup"
> version="1"
> PermissionSetName="FullTrust"
> Name="AWCLibrary">
> <IMembershipCondition
> class="UrlMembershipCondition"
> version="1"
> Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
>Services\ReportServer\bin\ReportHelper.dll"/>
></CodeGroup>
>I write to my log file as follows:
>public static void WriteLogFile(String msg)
> {
> FileIOPermission perm1 = new
>FileIOPermission(FileIOPermissionAccess.Write, @."C:\ReportHelper.log");
> perm1.Assert();
> //try
> //{
> FileStream fs = new FileStream(@."C:\ReportHelper.log",
>FileMode.OpenOrCreate, FileAccess.ReadWrite);
> StreamWriter w = new StreamWriter(fs);
> w.BaseStream.Seek(0, SeekOrigin.End);
> w.Write("{0} {1} ", DateTime.Now.ToLongTimeString(),
> DateTime.Now.ToLongDateString());
> w.Write(msg + "\r\n");
> w.Flush();
> w.Close();
> }
>What am I missing here? Any help would be appreciated.
>Thanks!
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200507/1|||Hi Balaji,
I followed the article and it still doesn't work. I added [assembly:
AllowPartiallyTrustedCallers] to my assembly and removed extra
PermissionSet and CodeGroup sections from my policy file (I left the
"FullTrust" one) and I still get FileIOPermission error.
Thanks,
Kris
BALAJI via SQLMonster.com wrote:
> Check this
> http://www.c-sharpcorner.com/Code/2005/June/CustomAssemblyinRS.asp
> HTH
> If still you face the issue, let me know (bkkrishnan [at] hotmail [dot] com)
> Thanks
> Balaji
>
> Siwy wrote:
> >I got my custom assembly working fine until I add writing to a log
> >file. Then I get a FileIOPermission error.
> >
> >I have the following code in my policy file:
> >
> ><PermissionSet
> > class="NamedPermissionSet"
> > version="1"
> > Name="ReportHelperFilePermissionSet"
> > Description="A special permission set that grants read access to my
> >currency rates file.">
> > <IPermission
> > class="FileIOPermission"
> > version="1"
> > All="C:\ReportHelper.log"/>
> > <IPermission
> > class="SecurityPermission"
> > version="1"
> > Flags="Execution, Assertion"/>
> ></PermissionSet>
> >
> ><CodeGroup class="UnionCodeGroup"
> > version="1"
> > PermissionSetName="ReportHelperFilePermissionSet"
> > Name="MyNewCodeGroup"
> > Description="A special code group for my custom assembly.">
> > <IMembershipCondition
> > class="UrlMembershipCondition"
> > version="1"
> > Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
> >Services\ReportServer\bin\ReportHelper.dll"/>
> ></CodeGroup>
> ><CodeGroup
> > class="UnionCodeGroup"
> > version="1"
> > PermissionSetName="FullTrust"
> > Name="AWCLibrary">
> > <IMembershipCondition
> > class="UrlMembershipCondition"
> > version="1"
> > Url="D:\Program Files\Microsoft SQL Server\MSSQL\Reporting
> >Services\ReportServer\bin\ReportHelper.dll"/>
> ></CodeGroup>
> >
> >I write to my log file as follows:
> >
> >public static void WriteLogFile(String msg)
> > {
> > FileIOPermission perm1 = new
> >FileIOPermission(FileIOPermissionAccess.Write, @."C:\ReportHelper.log");
> > perm1.Assert();
> > //try
> > //{
> > FileStream fs = new FileStream(@."C:\ReportHelper.log",
> >FileMode.OpenOrCreate, FileAccess.ReadWrite);
> > StreamWriter w = new StreamWriter(fs);
> > w.BaseStream.Seek(0, SeekOrigin.End);
> > w.Write("{0} {1} ", DateTime.Now.ToLongTimeString(),
> > DateTime.Now.ToLongDateString());
> > w.Write(msg + "\r\n");
> > w.Flush();
> >
> > w.Close();
> > }
> >
> >What am I missing here? Any help would be appreciated.
> >
> >Thanks!
>
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200507/1
Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts
Wednesday, March 21, 2012
Friday, February 24, 2012
file operations
I'm writing a proc to do tlog backups. I want to validate the path before
attempting to issue the backup command but I don't see any documented file
handling funtions in T-SQL. What's the best approach for this?
Thanks,
Bob Castleman
DBA PoseurImplement a DTS package that first uses the FSO.FileExists function via a
ActiveX Script task to verify the folder. If the task returns success, then
use a Execute SQL task to call your SP.
Function Main()
Main = DTSTaskExecResult_Failure
sCopyFrom = "c:\temp\xxx.tmp"
sCopyTo = "c:\temp\xxx.dat"
set FSO = CreateObject("Scripting.FileSystemObject")
if not FSO.FileExists( sCopyFrom ) then
exit function
end if
if FSO.FileExists( sCopyTo ) then
FSO.DeleteFile sCopyTo
end if
FSO.CopyFile sCopyFrom, sCopyTo
set FSO = nothing
Main = DTSTaskExecResult_Success
End Function
"Bob Castleman" <nomail@.here> wrote in message
news:e180EavYFHA.1028@.TK2MSFTNGP10.phx.gbl...
> I'm writing a proc to do tlog backups. I want to validate the path before
> attempting to issue the backup command but I don't see any documented file
> handling funtions in T-SQL. What's the best approach for this?
> Thanks,
> Bob Castleman
> DBA Poseur
>
attempting to issue the backup command but I don't see any documented file
handling funtions in T-SQL. What's the best approach for this?
Thanks,
Bob Castleman
DBA PoseurImplement a DTS package that first uses the FSO.FileExists function via a
ActiveX Script task to verify the folder. If the task returns success, then
use a Execute SQL task to call your SP.
Function Main()
Main = DTSTaskExecResult_Failure
sCopyFrom = "c:\temp\xxx.tmp"
sCopyTo = "c:\temp\xxx.dat"
set FSO = CreateObject("Scripting.FileSystemObject")
if not FSO.FileExists( sCopyFrom ) then
exit function
end if
if FSO.FileExists( sCopyTo ) then
FSO.DeleteFile sCopyTo
end if
FSO.CopyFile sCopyFrom, sCopyTo
set FSO = nothing
Main = DTSTaskExecResult_Success
End Function
"Bob Castleman" <nomail@.here> wrote in message
news:e180EavYFHA.1028@.TK2MSFTNGP10.phx.gbl...
> I'm writing a proc to do tlog backups. I want to validate the path before
> attempting to issue the backup command but I don't see any documented file
> handling funtions in T-SQL. What's the best approach for this?
> Thanks,
> Bob Castleman
> DBA Poseur
>
Subscribe to:
Posts (Atom)