2

I keep getting the error message:

an exception occurred while executing a transact-sql statement or batch

when trying to do anything in SQL Server Management Studio 2016.

This occurs when I try to create or edit a login, when I try to create a new database, basically when I do anything.

I tried the solution given in SQL Server 2008 R2 Express permissions -- cannot create database or modify users but I can't edit the Startup Parameters specified in step 6.

Can anyone explain what the issue is and how to solve it?

Community
  • 1
  • 1
krishna
  • 163
  • 1
  • 2
  • 7
  • 2
    can you post the exact code you attempt to run in the batch. You say when you "do anything", what about `select 1`? – S3S Dec 28 '16 at 22:02
  • that's the thing. i haven't even created a database yet or coded anything. i have just installed the software and this error keeps happening from the get-go. – krishna Dec 28 '16 at 22:04
  • 2
    you are logging in as the sa account you set up during installation? – S3S Dec 28 '16 at 22:08
  • Did you right-click the installation and choose "Run as Administrator"? Also, check your permissions for each SQL service you're installing, especially the db-engine--best to use an Adminstrator-type account cheers – mike morris Dec 29 '16 at 01:43
  • Service account don't have permissions. Open configuration manager and get account name. Right click on folders (where is sql server, your default paths) and go to security and add user from conf. manager. Other options are firewall, security software, port config or there are missing system databases (like tempdb). Need more info. – Deadsheep39 Dec 29 '16 at 13:42
  • @mikemorris I have tried running it as administrator and I've given myself permissions as well. still getting the error message. – krishna Dec 29 '16 at 15:10
  • @Deadsheep39 i'm sorry, I don't understand what you mean. – krishna Dec 29 '16 at 15:11
  • I have no problem doing selects and other things, but I getthe same message when trying to restore a database. – MSIS Dec 18 '20 at 04:55

5 Answers5

2

I got this error message while trying to attach DB, if it's your case, go to to the folder where your DB is:

  • Right click => properties => security => advanced
  • Make sure the correct user has 'full control' permission
  • If not:
    • Click on 'Change permissions'
    • Set 'full control' permission to the relevant user (or all of them)
  • Try to attach again

It works for me.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
1

Thanks to everyone who tried to answer the question, but I was able to solve it. It is the same procedure mentioned in SQL Server 2008 R2 Express permissions -- cannot create database or modify users. However, in step 6 instead of adding "-m" to an existing parameter, you have to create a new parameter called "-m" and follow the remaining steps. This resolved the issue.

Community
  • 1
  • 1
krishna
  • 163
  • 1
  • 2
  • 7
1

I got same issue but when i tried with query it was succeeded. try below

CREATE DATABASE databasename;
Lahiru Gamage
  • 849
  • 5
  • 14
  • 27
0

I fixed it a different way
I put the .bak file in "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup"

user16714199
  • 228
  • 6
  • 19
0

sometimes it happens because of the "file" that you are trying to "restore"! I mean, you have to check the "file"! The file might be a "query" by itself! and so, there will be no necessity to "restore" it! and then, your job is only "opening" it using the Microsoft SQL Server Management Studio (SSMS)! fingers crossed!