LINQ to SQL SubmitChanges 不起作用 FILESTREAM 表
我有一些代码将数据插入到一些表中(一个表有一个 FILESTREAM 列),然后在完成后调用 SubmitChanges。
db.Log = new System.IO.StreamWriter(@"c:\windows\temp\linq.log") { AutoFlush = true };
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
我引用了以下链接,但它们似乎不是我的问题:
LINQ to SQL : SubmitChanges() 不起作用?
每个表都有一个主键。
我有 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我忘记了交易中完整的声明
I forgot the completed statement inside of the transaction
大约一个月前,我从代码向 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.