SQL'EXECUTE AS'login命令和LINQ to SQL [英] SQL 'Execute As' Login Command and Linq to SQL
问题描述
我想执行使用EXECUTE AS命令的SQL查询的其他登录。我使用LINQ到SQL,所以我产生一个数据上下文类和我使用executeQuery方法来运行EXECUTE ASSQL命令。那么我所说的LINQ到SQL命令是成功的。然而,每一个后续查询失败,出现以下错误:
I am trying to execute a sql query as another login using the 'Execute As' command. I am using Linq to SQL, so I've generated a Data Context class and I am using the ExecuteQuery method to run the 'Execute As' SQL command. I then call a Linq to SQL command that is successful. However, every subsequent query fails with the following error:
当前命令发生了严重错误。结果,如果有的话,应被丢弃。
A severe error occurred on the current command. The results, if any, should be discarded.
下面是我曾尝试code片断:
Here is the code snippet that I have tried:
SummaryDataContext summary = new SummaryDataContext();
summary.ExecuteQuery<CustomPostResult>(@"Execute as Login='Titan\Administrator'");
var test = summary.Customers.First();
var test2 = summary.Products.ToList();
无论我运行我收到错误消息从上面的第二个查询什么查询。任何帮助将是AP preciated。
No matter what query I run on the second query I receive the error message from above. Any help would be appreciated.
推荐答案
我设法通过使用ADO.NET类执行查询来解决这个问题,在我的应用程序。
I managed to get around this issue in my application by executing the query using ADO.NET classes.
SqlCommand cmd = new SqlCommand("EXECUTE AS USER = 'operator'");
cmd.Connection = dc.Connection as SqlConnection;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
// do the rest of the queries using linq to sql
这篇关于SQL'EXECUTE AS'login命令和LINQ to SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!