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?
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?
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_datareaderdatabase 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 withdb_datawriter.For more information, read Get started with Database Engine permissions