LINQ to SQL SubmitChanges 不起作用 FILESTREAM 表

发布于 2024-09-29 00:52:34 字数 3684 浏览 5 评论 0原文

我有一些代码将数据插入到一些表中(一个表有一个 FILESTREAM 列),然后在完成后调用 SubmitChanges。

db.Log = new System.IO.StreamWriter(@"c:\windows\temp\linq.log") { AutoFlush = true };
db.SubmitChanges(ConflictMode.FailOnFirstConflict);

我引用了以下链接,但它们似乎不是我的问题:

LINQ to SQL : SubmitChanges() 不起作用?

LINQ 未在 .SubmitChanges() 上更新

每个表都有一个主键。 alt text

我有 14 个表,我看到 linq.designer.cs 中包含 14 个 IsPrimaryKey=true

虽然我确实看到了文件表中缺少“AutoSync=AutoSync.OnInsert”,但我认为这是因为未设置 IDENTITY(使用 guid 作为主键)。

当我检查数据库时,没有任何内容插入其中。 linq.log 显示:

INSERT INTO [dbo].[Files]([fileID], [FileContents], [dteCreated], [dteLastModified], [txtDesc], [mimeID], [txtName], [txtTitle], [dteDeleted])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8)
-- @p0: Input UniqueIdentifier (Size = -1; Prec = 0; Scale = 0) [92190315-1107-4848-94b3-dd9badf4465b]
-- @p1: Input VarBinary (Size = -1; Prec = 0; Scale = 0) [SqlBinary(24064)]
-- @p2: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) [10/26/2010 1:54:55 PM]
-- @p3: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) [10/26/2010 1:54:55 PM]
-- @p4: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [This is my new file]
-- @p5: Input Int (Size = -1; Prec = 0; Scale = 0) [3]
-- @p6: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [MySecondTestDoc.doc]
-- @p7: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [My Other Test Document]
-- @p8: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) []
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

INSERT INTO [dbo].[UserFiles]([fileID], [userID], [rightsID])
VALUES (@p0, @p1, @p2)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input UniqueIdentifier (Size = -1; Prec = 0; Scale = 0) [92190315-1107-4848-94b3-dd9badf4465b]
-- @p1: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
-- @p2: Input Int (Size = -1; Prec = 0; Scale = 0) [3]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

当我查看 Server Profiler 时,它记录 RPC:Completed exec sp_executesql "Good Insert Statement"

当我通过 Server Manager Studio 手动运行 sql 时,一切正常。我可以通过使用 SA 或 Web 服务使用的凭据登录来成功完成此操作。

但 LINQ SubmitChanges 不会引发错误。它不工作有什么原因吗?我没有在任何部分类中重载任何 Insert/Update/DeleteFile 函数。

修改其他表似乎工作正常。我想知道这是否与 FILESTREAM 列有关。

我的连接字符串是:

Data Source=IP;Initial Catalog=MyDB;User ID=myLogin;Password=myPswd

一旦我手动将记录放入表(FILESTREAM 表)中,我就可以很好地读取该数据。

最后,我将 FILESTREAM 配置为用于 Transact-SQL 访问,而不是用于文件 I/O 流访问。根据我的理解,我认为数据位置不需要共享文件夹。我希望所有内容都通过数据库来获取 FILESTREAM 数据。

谢谢!

已修复

我有以下代码:

public TransactionScope CreateTransactionScope(TransactionScopeOption scope, IsolationLevel level)
{
  var transactionOptions = new TransactionOptions();
  transactionOptions.IsolationLevel = level;
  transactionOptions.Timeout = TimeSpan.MaxValue;
  return new TransactionScope(scope, transactionOptions);
}
public TransactionScope CreateTransactionScope(TransactionScopeOption scope)
{
  return CreateTransactionScope(scope, IsolationLevel.ReadCommitted);
}

我的提交更改看起来像:

using (var ts = db.CreateTransactionScope(TransactionScopeOption.RequiresNew, IsolationLevel.ReadUncommitted))
    {
      db.SubmitChanges(ConflictMode.FailOnFirstConflict);
    }

有人吗?有人吗?我忘记了完整的声明...哈哈。我想我可能会在提交更改区域添加更多内容,并且可能想要回滚,所以我将 using 语句留在那里,但从未提交我的更改...谢谢大家!

I have some code that inserts data into some tables (one table has a FILESTREAM column) and then calls SubmitChanges after it is done.

db.Log = new System.IO.StreamWriter(@"c:\windows\temp\linq.log") { AutoFlush = true };
db.SubmitChanges(ConflictMode.FailOnFirstConflict);

I have referenced the following links but they appear to not be my issue:

LINQ to SQL: SubmitChanges() does not work?

LINQ not updating on .SubmitChanges()

Each table has a primary key.
alt text

I have 14 tables and I see 14 IsPrimaryKey=true contained in the linq.designer.cs

Though I do see that "AutoSync=AutoSync.OnInsert" is missing from the Files table but I think that is because IDENTITY is not set (using guid as primary key).

When I check the database, nothing was inserted into it. The linq.log shows:

INSERT INTO [dbo].[Files]([fileID], [FileContents], [dteCreated], [dteLastModified], [txtDesc], [mimeID], [txtName], [txtTitle], [dteDeleted])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8)
-- @p0: Input UniqueIdentifier (Size = -1; Prec = 0; Scale = 0) [92190315-1107-4848-94b3-dd9badf4465b]
-- @p1: Input VarBinary (Size = -1; Prec = 0; Scale = 0) [SqlBinary(24064)]
-- @p2: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) [10/26/2010 1:54:55 PM]
-- @p3: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) [10/26/2010 1:54:55 PM]
-- @p4: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [This is my new file]
-- @p5: Input Int (Size = -1; Prec = 0; Scale = 0) [3]
-- @p6: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [MySecondTestDoc.doc]
-- @p7: Input VarChar (Size = 8000; Prec = 0; Scale = 0) [My Other Test Document]
-- @p8: Input DateTime2 (Size = -1; Prec = 0; Scale = 0) []
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

INSERT INTO [dbo].[UserFiles]([fileID], [userID], [rightsID])
VALUES (@p0, @p1, @p2)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]
-- @p0: Input UniqueIdentifier (Size = -1; Prec = 0; Scale = 0) [92190315-1107-4848-94b3-dd9badf4465b]
-- @p1: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
-- @p2: Input Int (Size = -1; Prec = 0; Scale = 0) [3]
-- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 4.0.30319.1

When I look at Server Profiler it records RPC:Completed exec sp_executesql "Good Insert Statement"

When I run the sql manually through Server Manager Studio, everything works fine. I can do that successfully either by logging in with SA or with the credentials used by the web service.

LINQ SubmitChanges is not throwing an error though. Any reason why it is not working? I have not overloaded any Insert/Update/DeleteFile functions in any partial classes.

Modifying other tables seem to work fine though. I am wondering if it has to do with the FILESTREAM column.

My connection string is:

Data Source=IP;Initial Catalog=MyDB;User ID=myLogin;Password=myPswd

Once I manually put the record into the table (FILESTREAM table), I can read that data just fine.

Lastly, I have FILESTREAM configured for Transact-SQL access and not for file i/o streaming access. From how I understood it, I didn't see a need to have a shared folder to the data location. I wanted everything to go through the database to get to the FILESTREAM data.

Thanks!

FIXED

I have the following code:

public TransactionScope CreateTransactionScope(TransactionScopeOption scope, IsolationLevel level)
{
  var transactionOptions = new TransactionOptions();
  transactionOptions.IsolationLevel = level;
  transactionOptions.Timeout = TimeSpan.MaxValue;
  return new TransactionScope(scope, transactionOptions);
}
public TransactionScope CreateTransactionScope(TransactionScopeOption scope)
{
  return CreateTransactionScope(scope, IsolationLevel.ReadCommitted);
}

and my submitchanges looked like:

using (var ts = db.CreateTransactionScope(TransactionScopeOption.RequiresNew, IsolationLevel.ReadUncommitted))
    {
      db.SubmitChanges(ConflictMode.FailOnFirstConflict);
    }

anyone? anyone? I forgot the complete statement... lol. I was thinking that I might add more in the submitchanges area and might want to rollback so I left the using statement there but never commit my changes... Thanks everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女的英雄梦 2024-10-06 00:52:34

我忘记了交易中完整的声明

I forgot the completed statement inside of the transaction

笛声青案梦长安 2024-10-06 00:52:34

大约一个月前,我从代码向 SQL Server 发送了一个插入查询。并眼睁睁地看着什么都没有发生。没有插入记录,也没有记录错误。 Profiler 显示正在提交的查询。如果我运行探查器的查询,那么它就起作用了。绝对让我困惑。

然后,我兴致勃勃地检查了安全情况。你瞧,执行该站点的用户没有执行插入的权限。更新安全性后,一切开始正常工作。

奇怪的是,绝对没有抛出任何错误。当我尝试重现该问题时,我开始出现安全错误。我认为 SQL Server 只是决定那天不报告任何内容。

你可以从那里开始。

About a month ago I sent an insert query from code to the sql server. And watched absolutely nothing happen. No records were inserted and no errors recorded. Profiler showed the query being submitted. If I ran the query that profiler had, then it worked. Absolutely boggled my mind.

Then, on a lark, I checked on the security. Lo and behold the user the site was executing under did not have permissions to perform the insert. After updating the security, everything started working just fine.

Weird thing is that absolutely no error was thrown. When I tried to replicate the problem, I started getting security errors. I figured SQL server just decided not to report any that day.

You might start there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文