为什么我会收到 SqlClientPermission 异常?
我构建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最有可能的是,该程序没有在完全信任的情况下执行。要么是因为计算机是这样配置的,要么是您从网络共享运行它...
可以找到更多信息 在这里。
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.
授予数据库的执行用户权限。
Grant the executing user rights to the database.
好吧,这是多种因素的结合,才达到了目的...
感谢所有帮助人员:-)!
Well It was a combination of things that did the trick...
Thanks for all the help guys :-)!!
如果你想远程连接到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