SQL Server DML operation should not be allowed while reading SQL query from .txt file

jogvjijk  于 2023-04-10  发布在  其他
关注(0)|答案(1)|浏览(127)

My SQL query is stored in a .txt file, and with the help of C#, I'm reading that query and fetching data from the database.

I want to make sure no DML operation should be performed. How to achieve this?

slmsl1lt

slmsl1lt1#

The safest and easiest way to do it is to connect your C# application to SQL Server with a user that doesn't have permissions to run DML statements.

If your application should only be able to read data, you can give your sql user a db_datareader database role. If it should also be able to add, update or delete data (which is, in fact, DML - writing my answer I was thinking of DDL for some reason), combine it with db_datawriter .

For more information, read Get started with Database Engine permissions

相关问题