In my C#.NET application, I use Microsoft.SqlServer.Management.Server.ConnectionContext.ExecuteNonQuery() to run a script against a SQL Server database.
I would like to know if there is a way to make sure the script does not contain “USE” statement.
I have to make sure the script is ran against a specific database and that it does not change DB while executing.
Thanks!
The way you control that in sql server is through security. You create a user account in sql server that only had read access, and only for that one database, and then make sure to use that account when connecting to the server. If that means using a different connection here than at other points in your app, so be it.