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

102 views Asked by At

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?

1

There are 1 answers

0
Zohar Peled On

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