Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

SQL CLR UDF

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
songstre - 16 Feb 2008 14:06 GMT
am currently trying to write a very simple UDF that checks for the
existence of a file. If the file does not exist it should return
null.
It doesn't seem to see the file even when it exists, however. I've
checked and rechecked and the file is there. HELP!
I tried using both UNC and mapped drive.

   [Microsoft.SqlServer.Server.SqlFunction(DataAccess =
DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)]

[System.Security.Permissions.PrincipalPermission(System.Security.Permission­
s.SecurityAction.Demand)]
   public static SqlString GetPictureUrl(string accountName)
   {
       try
       {
           if (accountName == null || accountName == string.Empty)
               return SqlString.Null;
           else if (System.IO.File.Exists(@"Y:\Hr\OurPeople\WhosWho
\photos\big\" + aname + ".jpg"))
               return new SqlString("http://mh000xsiis01/hr/
ourpeople/
whoswho/photos/big/" + aname + ".jpg");
           else
               return SqlString.Null;

       }
       catch (Exception exc)
       {

           throw exc;
       }
   }
Nicholas Paldino [.NET/C# MVP] - 16 Feb 2008 15:58 GMT
What is the account that this is running for?  Are you using SQL Server
accounts, or windows impersonation?  This is important, as you have to make
sure that the mapping for the Y drive exists for the user that this is
running for.

   Regardless, it's a bad idea to access the Y drive (assuming it is mapped
to a network drive) with a mapping, as mappings are user-specific, and I
don't think you know who the user is that is accessing the stored procedure
(is it the account the server is set up to use, or are you using trusted
connections and that's the user the stored procedure is running for?).

   On top of that, you have to make sure that whomever the user is, that
user has access to the file, otherwise, I don't believe Exists will return
true.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

am currently trying to write a very simple UDF that checks for the
existence of a file. If the file does not exist it should return
null.
It doesn't seem to see the file even when it exists, however. I've
checked and rechecked and the file is there. HELP!
I tried using both UNC and mapped drive.

   [Microsoft.SqlServer.Server.SqlFunction(DataAccess =
DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)]

[System.Security.Permissions.PrincipalPermission(System.Security.Permission­
s.SecurityAction.Demand)]
   public static SqlString GetPictureUrl(string accountName)
   {
       try
       {
           if (accountName == null || accountName == string.Empty)
               return SqlString.Null;
           else if (System.IO.File.Exists(@"Y:\Hr\OurPeople\WhosWho
\photos\big\" + aname + ".jpg"))
               return new SqlString("http://mh000xsiis01/hr/
ourpeople/
whoswho/photos/big/" + aname + ".jpg");
           else
               return SqlString.Null;

       }
       catch (Exception exc)
       {

           throw exc;
       }
   }
songstre - 22 Feb 2008 18:37 GMT
On Feb 16, 10:58 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
>     What is the account that this is running for?  Are you using SQL Server
> accounts, or windows impersonation?  This is important, as you have to make
[quoted text clipped - 48 lines]
>         }
>     }

Thanks Nicholas.

I am running it with Windows Auth on a dev box where I am an
administrator. I have access to the file as well. I'm thinking I need
to grant some kind of access to the function (I may have said Stored
Proc before, not true....SQL function). I did try it with a UNC as
well. Just wanted to try with a mapped drive to see if it made a diff.

Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.