【发布时间】:2019-12-14 09:08:30
【问题描述】:
我有一个具有完全非事务性访问权限的文件表。因此,它可以像任何文件服务器一样被浏览,也可以通过 T-SQL 直接插入。我编写了一个简单的 SQL CLR C# 来将文件从文件表复制到文件服务器。执行复制的用户是对 sql server(因此是文件表)和文件共享具有管理员权限的 sql 服务帐户。没有真正的权限错误。
```try
{
using (new ImpersonationNamespace.Impersonation(domain, username, password))
{
if (!Directory.Exists(sourceDirectory))
{
throw (new Exception("Source Directory: '" + sourceDirectory.ToString() + "' does not exist or user: "+ WindowsIdentity.GetCurrent().Name+" does not not have rights."));
}
if (!Directory.Exists(targetDirectory))
{
throw (new Exception("Target Directory: '" + targetDirectory.ToString() + "' does not exist or user: " + WindowsIdentity.GetCurrent().Name + " does not not have rights."));
}
if (!File.Exists(sourcePath))
{
throw (new Exception("Source File: '" + sourceFileName.ToString() + "' does not exist or user: " + WindowsIdentity.GetCurrent().Name + " does not not have rights."));
}
if (File.Exists(targetPath) && overwrite == false)
{
throw (new Exception("Target File: '" + targetFileName.ToString() + "' already exists in targeted directory: '" + targetDirectory.ToString() + "'"));
}
File.Copy(sourcePath, targetPath, overwrite);
}
}
catch (Exception ex)
{
throw ex;
}
```
消息 6522,级别 16,状态 1,过程 dbo.FileCopy_CLR,第 0 行 [批处理开始第 30 行] 在执行用户定义的例程或聚合“FileCopy_CLR”期间发生 .NET Framework 错误: System.Exception:源目录:'\sqlserver\filestreamname\FilestreamDirectoryName\Filetable\FlowInput\13143\' 不存在或用户:域\sqlserverserviceaccount 没有权限。 系统异常: 在 StoredProcedures.FileCopy(字符串 sourceDirectory,字符串 targetDirectory,字符串 sourceFileName,字符串 targetFileName,布尔覆盖,字符串域,字符串用户名,字符串密码) .
【问题讨论】:
标签: sql-server permissions filetable