Visual Studio(VS) lovers! Yes, we want to work on everything from within the VS. Yes, of course, our VS have required features to support us to perform various development and ALM operations. Database is one of the main parts of any application development. Instead of working on the database objects using SQL Server Management Studio, we prefer to use VS. Access the database directly from VS using the SQL Server Object Explorer. Moreover, we would like to work with the SQL express instead of connecting to a centralized database server for small project or at the starting of a project.
Even though we have Admin access, most of the time, we end up with permission issues in database level. This prevents us from create a database in SQL Express.
If you have Admin privilege in system, we can quickly fix this issue. Go to your services using Start> Run> services.msc. Locate the SQL Server (
SQLEXPRESS) service from the list of services.
Right click and select Properties.
Stop the service using the Stop option in the Properties window, if not stopped. Now, enter
-m into the Start parameters text box to start the SQL express service in Single used mode.
Start the service using Start option in the Properties window.
Go to command prompt using Start>Run>cmd and run the following commands to add the domain user as a sysadmin to SQL express.
Note: Replace domain\user with the corresponding domain user information before running the following command.
osql -S .\sqlexpress -E
create login [domain\user] from windows
exec sp_addsrvrolemember @loginame= ‘domain\user’, @rolename='sysadmin'
Once the command execution completes, navigate back to the services window and stop the SQL Express service. Remove
-m from Start parameters and start the SQL express service to support multiple users.
Now, we can create a new database using Visual Studio’s SQL Server Object Explorer and perform our database operations.