Accessing Database object throws error when using SMO with App Role

51 Views Asked by At

We use SQL SMO to manipulate SQL Db objects. The functionality works fine but I need to make it work with the application role now. I am getting following error whenever I access the database object (of type "Microsoft.SqlServer.Management.Smo.Database") after I enable the application role at the connection level. How do I go about enabling the application role for SQL SMO objects, so that I can create/alter/update Db objects using SQL SMO?

Error: The current user account was invoked with SETUSER or SP_SETAPPROLE. Changing databases is not allowed.

Following statement throws error if the application role was set at the connection level. I tried enabling the application role after I retrieve the myDB object as well. But, I get the same error as above, anytime I use myDB Object later in the function.

myDB = myServer.Databases[dbName];

0

There are 0 best solutions below