Read only queries Using ADO.NET

混江龙づ霸主 提交于 2019-12-20 06:43:09

问题


I want to limit the application to read only queries. In other words, I want the application to process only those queries which are not changing the state of the database. I am using ADO.NET. I do not want to create a new user against the database with read only permissions. Any suggestions are welcome.


回答1:


Option 1: SQL Authentication

You can use connections as shown below:

Server ={serverName}; Initial Catalog = {DB_Name}; User Id={uid}; Password={pwd};

Use the uid which has only read access in database.

Option 2: Windows Authentication

If you want to use Integrated Security = True; (i.e. windows authentication) then you will have to grant readonly access to the windows user (under which the program runs).

Hope this helps.




回答2:


You can create triggers to cancel any insert update or delete through a trigger at the database level. The trigger would end with a rollback to cancel the transaction. You would have to figure out who kicked off the trigger so other users can update the db.

I would not do it - I would take away any permission (except select) from the account being used for the application. I have created many, many triggers but I have never heard anyone using database triggers to enforce read only.



来源:https://stackoverflow.com/questions/54259947/read-only-queries-using-ado-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!