为什么我会收到 SqlClientPermission 异常?

发布于 2024-11-06 08:54:25 字数 572 浏览 0 评论 0原文

我构建了一个 C# WinForms 应用程序,它访问 SQL Server 2008 进行数据操作。

该应用程序在开发的机器上运行良好。但是,当我复制 EXE 并将其移动到另一台计算机(Windows XP)时,在登录系统期间(换句话说,当我访问数据库时)出现以下错误。

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

这是我的连接字符串:

Data Source=vmsql;Integrated Security=SSPI;Initial Catalog=ChequeBookInventory

堆栈跟踪在屏幕截图中给出

知道如何解决此问题吗? !

I have built a C# WinForms application which accesses a SQL Server 2008 for data manipulation.

The application works fine on the machine that was developed on. However when I copy the EXEs and move it to another computer (Windows XP), I got the following error during the login to the system (in other words, when i access the database).

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

Here's my connection string:

Data Source=vmsql;Integrated Security=SSPI;Initial Catalog=ChequeBookInventory

Stack trace is given in a screen shot

Any idea how to fix this issue?!

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

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

发布评论

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

评论(4

烟酉 2024-11-13 08:54:25

最有可能的是,该程序没有在完全信任的情况下执行。要么是因为计算机是这样配置的,要么是您从网络共享运行它...
可以找到更多信息 在这里

Most likely, the program is not executed with full trust. Either because the computer is configured like this or you are running it from a network share...
Some more info can be found here.

迷路的信 2024-11-13 08:54:25

授予数据库的执行用户权限。

Grant the executing user rights to the database.

豆芽 2024-11-13 08:54:25

好吧,这是多种因素的结合,才达到了目的...

  1. 设置代码级访问...我已经允许通过 .NET Fx 配置在网络共享 URL 的机器级别上完全信任(我必须单独安装)
  2. 安装 .NET 最新版本版本..(我坚持使用 3.5 ;-] )

感谢所有帮助人员:-)!

Well It was a combination of things that did the trick...

  1. Setup code level access... I had allow full trust on machine level that network share URL through .NET Fx configuration (Whc i had to install seperately)
  2. Install .NET latest version.. (I stuck to 3.5 ;-] )

Thanks for all the help guys :-)!!

寂寞笑我太脆弱 2024-11-13 08:54:25

如果你想远程连接到SQL Server,并且不想使用用户名和密码而是使用Windows身份验证,那只是一种方法 - “AD”,我认为AD可能会导致更多问题(但AD更安全),我对于我的答案不正确,我真的很抱歉,我找到了一些关于该问题的参考资料,我认为这可能会有所帮助。

1.如何解决“无法生成 SSPI 上下文”错误消息

2.“无法生成 SSPI 上下文”错误消息,SQL Server 的更多注释

3.“无法生成 SSPI 上下文”错误连接到域外本地 SQL Server 时的消息

4.服务主体名称 (Windows)

5.“访问被拒绝”当您尝试访问远程资源时出现错误消息

这是错误的答案:

如果您使用“Integrated Security=SSPI”,则意味着您无法远程连接到 SQL Server。

如果您想远程连接,请使用“User Id=myUsername;Password=myPassword;”而不是“Integrated Security=SSPI”

(当然你的SQL Server必须接受“远程连接”)连接用于连接数据源的字符串

If you want to connect to SQL Server remotely, and don't want use the username and password but Windows Authentication, that's just one way - "AD" ,I think AD might cause more problems (but AD is more secure), and I am really sorry about that my answer is not correct, I found some references about that issue,I think it might be help.

1.How to troubleshoot the "Cannot generate SSPI context" error message

2.“Cannot Generate SSPI Context” error message, more comments for SQL Server

3.“Cannot generate SSPI context” error message, when connect to local SQL Server outside domain

4.Service Principal Names (Windows)

5."Access Denied" error message when you try to access remote resources

that's bad answer bellow:

If you use "Integrated Security=SSPI", that means you can't connect to SQL Server remotely.

if you want to connect remotely, please use "User Id=myUsername;Password=myPassword;" instead of "Integrated Security=SSPI".

(Of course your SQL Server must accept "remote connection")connection string for connecting to data sources

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