I have written a Windows application in C# that connects to a SQL Server database. I run this query from inside the application to create SQL Server user authentication that is presumably hidden from PC user:
SET @LoginName = 'TestAdmin'
SET @Password = 'pass@word1'
-- Create user
SET @SQL = 'Create Login ' + @LoginName + ' with Password = ''' + @Password + ''''
EXEC sp_executesql @SQL
-- Adding user to sysadmin role
EXEC sp_addsrvrolemember @LoginName, 'sysadmin'
I am planning to upload a .SQL
file to create database with tables and data, all that to be done programmatically from the application. I do not want application user or PC owner to have full access to this database.
The problem:
When I go to SQL Server Management Studio, as a user, I can simply connect to database using Windows authentication and have full access to database tables and data! How can I prevent that? I want only that application to have access to its database?