locked
CLR probléma RRS feed

  • Question

  • Sziasztok!

    Van az alábbi c#-ban irt CLR-m tárolteljárásom(Normál C# programként műkődik)

    A problémám a következő, mikor ez a sor  if (FileFound = File.Exists(FileName) == true)

    nincs ki kommentezve a akkor a tárolteljárásom lefut, de nem ad eredményt.

    Ha ki kommentezem akkor megprobálja végrehajtani, de a következő hibaüzenetet kapom:

    Hello world!

    c:\be.txt

    Hello world!

    3

    Msg 6522, Level 16, State 1, Procedure usp_FileExists, Line 0

    A .NET Framework error occurred during execution of user-defined routine or aggregate "usp_FileExists":

    System.Exception: Error executing FileInfo. ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    System.Security.SecurityException:

       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

       at System.Security.CodeAccessPermission.Demand()

       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, FileOptions options)

       at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)

       at System.IO.StreamReader..ctor(String path)

       at StoredProcedures.FileExists()

    System.Exception:

       at StoredProcedures.FileExists()

    .

    Esetleg egy CLR debugger programot nem tudtok ajánlani SQL2005Exp-hez és VS2005 Exp pároshoz?

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Data;

    using System.Data.Sql;

    using System.Data.SqlTypes;

    using Microsoft.SqlServer.Server;

    using System.IO;

    public partial class StoredProcedures

    {

        [SqlProcedure]

        public static void FileExists()

        {

            SqlPipe SQLPipe = SqlContext.Pipe;

            string FileName;

            FileName = "c:\\be.txt";

            SqlContext.Pipe.Send("Hello world!");

            //FileInfo myFile = new FileInfo("c:\\delimeted.txt");

            Boolean FileFound = false;

            try

            {

                SqlContext.Pipe.Send(FileName);

                if (FileFound = File.Exists(FileName) == true)

                {

                    SqlContext.Pipe.Send("Hello world!");

                    //comma delimeted file

                    string nextLine;

                    SqlContext.Pipe.Send("3");

                    StreamReader streamReader = new StreamReader(FileName);

                    while ((nextLine = streamReader.ReadLine()) != null)

                    {

                        //break it up

                        SqlContext.Pipe.Send("4");

                        string[] words = nextLine.Split(';');

                        for (int i = 0; i < 13; i++)

                        {

                            //do something intersting here

                            //Console.WriteLine(wordsIdea);

                            SqlContext.Pipe.Send(wordsIdea);

                        }

                    }

                    //cleanup

                    streamReader.Close();

                    SqlContext.Pipe.Send("Close !");

                }

            }

            catch (Exception exp)

            {

                throw new Exception("Error executing FileInfo.", exp);

               

            }

            SqlContext.Pipe.Send("Stop");

        }

    }

    Friday, November 9, 2007 9:23 AM

All replies

  • Hali,

     

    Tudtommal alapban a CLR tárolt eljárásnak nincs joga külső fájlműveletet végrehajtani:

    http://msdn2.microsoft.com/en-us/library/ms254940(VS.80).aspx

     

    üdv,

    Zoli

     

    Friday, November 9, 2007 10:50 AM
  • Szia Zoli,

     

    Köszi a linkel beinditottál egy gondolat sort. Hál istennek lehet.

    Sáfár Istvánnak volt egy válasza egy CLR problémára és ott volt az alábbi sor.

    alter database dbName set TRUSTWORTHY on

    és ezt

    WITH PERMISSION_SET = SAFE erre kellet cserélni

    WITH PERMISSION_SET = EXTERNAL_ACCESS

    .

    Innentől kezdve oké a feldolgozás.

    Köszönöm a segítséget. 

    Esetleg nem tudsz egy debuggert a VS2005 express SQL2005 Express kombinációhoz?

    Friday, November 9, 2007 4:15 PM