Can't connect to SQL Server 2008 database - sql

We have a SQL Server SSIS ETL package. It simply looks to take data from a source db & synchronises it into a target database. Connection parameters are inserted into a XML config file. Been advised we only require SELECT/View permissions on the source but whenever we run the package we get errors stating the service account login has failed & can't open database requested by login.
On a basic SQL Server Management Studio level I can see the account has public access at the instance level but has no permission assigned at the database level. From database properties/permissions I can see the grant box has been ticked for Select access.
I'm not familiar really with how Select/View access grants work, but surely it needs to have some permission defined at the database level; should it not need db_datareader as a minimum?

Related

How do I add additional active directory logins to an Azure database?

I have been able to set up an active directory login for my Azure database.
Now I want to add additional active directory logins and set their permissions
I understand that I need to use Management Studio to do this and have installed SSMS v17.8.1
I have been studying docs but I can't find the instructions
[Update]
After reading Conor's answer I was able to create the user
CREATE USER [jobuser#mydomain] FROM EXTERNAL PROVIDER WITH DEFAULT_SCHEMA=[dbo]
However if I try to login using MSSMS with Active Directory - Password authentication I get
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON' (MIcrosoft SQL Server, Error 18456)
[Update]
In the Connection Properties Tab
I had to overtype with the database name
That particular page only shows an example using a SQL login/user, so I can understand why you are confused.
Please read through this page:
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-user-transact-sql?view=sql-server-2017
Specifically, you want to create a user using the AS EXTERNAL PROVIDER example. This tells SQL Azure (and SQL DW) to use Azure Active Directory instead of creating a SQL user. Please note that this does not (as of today) work in SQL Server. (SQL Server supports integrated authentication against a local Active Directory, but it just does not currently support the Azure Active Directory service).
Also, there is no specific requirement that you use SSMS to do this step. You can do it within SSMS, SQL Operation Studio, through one of the SQL client drivers in a program you write (or some third party program that can invoke SQL over them), sqlcmd, etc. You don't even need to have the latest SSMS to make things work (though it is recommend to get the best experience against SQL Azure including syntax highlighting).
Please give that a try and see if it gets you unblocked.
Best of Luck!

Sql Server grant permission for sp_grantdbaccess on a newly restored DB

I am unable to grant access to a newly restored database using sp_grantdbaccess. I am trying to do this via dynamic sql like below.
DECLARE #grant_access nvarchar(500)
SET #grant_access = 'EXEC ' + #new_db_name + '.dbo.sp_grantdbaccess ''IIS APPPOOL\myApp'''
EXEC sp_executesql #grant_access
I get the below error back trying to run this from a sproc. Any ideas on how I can grant permission for the app to call sp_grantdbaccess etc? I guess I am needing permission to give permission...
Error restore_backup restore_new_configDBThe server principal "IIS
APPPOOL\myApp" is not able to access the database "new_db_name" under
the current security context
Based on the error message it looks like you are trying to grant access to IIS APPPOOL\myApp using the security context IIS APPPOOL\myApp, but IIS APPPOOL\myApp doesn't have the access rights to the db to grant access rights to itself. I think this is akin to me trying to grant myself access to my neighbors house, but I don't have any authority to do so.
Depending on what type of security policies you are working under, I would either run the app pool under an account that has the greater privileges through integrated auth (but this might negate your need to grant privileges), or execute these SQL statements using a local SQL account with the necessary privileges to the database. In these cases, it would be like asking my neighbor (elevated access) to let me (IIS APPPOOL\myApp) in.
If you think it should work because IIS APPPOOL\myApp had access to the DB prior to being backed up, could this be a problem with IIS APPPOOL\myApp being an orphaned user? See http://msdn.microsoft.com/en-us/library/ms175475.aspx But with this case, you still might run into the above scenario trying to fix the orphaned user.

How to enable permissions in SQL Server 2012 FileTable folder share?

After successfully creating a FileTable, I tried viewing the fileshare but my permissions are denied. In Management Studio, right-clicking on FileTable then "Explore FilteTable Directory" gives me the following error message:
The File location cannot be opened. Either access is not enabled or
your do not have permissions for the same.
If I try to manually reach the share using \mycomputer\sqlexpress..., I'm still denied access.
This is SQL Express running on my local machine. I'm accessing this share from the same machine. What am I missing?
Does the windows user you are trying to access the fileshare as have SQL server access to the filetable database? Windows share permissions don't apply to filestream shares so, make sure you have permissions in the SQL database.
The other things you need to check to make sure you have access are the setting in configuration manager to ensure that Transact-SQL access is enabled as well as file I/O access (you can also set here whether clients can connect to the share remotely too).
To access these settings, open SQL Server configuration manager, in SQL server services, right click on the SQL Server Service for your instance and select properties, on the filestream tab you will see the options.
The next place you need to check for settings (yes, you have to enable this feature in 3 separate places!) is the level of access on the SQL server itself.
Open SQL Server Management Studio, connect to your SQL instance and right click on your server and select properties. Click on the advanced section and there is a section for filestream, you need to select full access enabled if you want to use filetable.
I actually found this article after typing all of that which explains how to enable the pre-requisites for filetables:
Enable the Prerequisites for FileTable
Hope this helps.
For me, since my server is a networked server, the resolution was:
Step into SQL Server Configuration Manager
Open SQL Server Services
Right click on SQL Server (MSSQLSERVER) and go to properties
Go to the FILESTREAM tab and make sure Allow remote clients access to FILESTEAM data is checked
Can you check a few things?
Can you via Windows Explorer try to browse to each of the following:
\\YOURCOMPUTERNAME
\\YOURCOMPUTERNAME\[FILESTREAM Share Name]\ e.g MSSQLSERVER
\\YOURCOMPUTERNAME\[FILESTREAM Share Name]\[FILESTREAM Directory Name]
\\YOURCOMPUTERNAME\[FILESTREAM Share Name]\[FILESTREAM Directory Name]\[FILETABLE Table Name]
[FILESTREAM Share Name]
this is the name as defined at the Server Insance level when you set FILESTREAM access up
to check it, right click on the Server Connection in SSMS and choose Properties
then look in Advanced --> FILESTREAM --> FILESTREAM Share Name
[FILESTREAM Directory Name]
this is the name as defined in the database when you set FILESTREAM
access up
to check it, right click on the Database in SSMS and choose Properties
then look in Options --> FILESTREAM --> FILESTREAM Directory Name
[FILETABLE Table Name]
Remember when you name your table it has to conform with Windows Folder naming rules (ie avoid special characters) e.g "TABLE|WEIRDCHARACTER"
Note(1): I have found that if you give your user only "ALTER" permission on the Filetable Table it will be browseable at the
\\YOURCOMPUTER\MSSQLSERVER\FILESTREAM_DIRECTORY_NAME\
level but you wont actually be able to browse the contents of the "directory"
Note(2): if you only give SELECT, UPDATE, DELETE, INSERT permission to a user on a filetable Table it will be able to access the folder with the fullpath and see the contents and act on them - create new files, modify existing files
\\YOURCOMPUTER\MSSQLSERVER\FILESTREAM_DIRECTORY_NAME\FILETABLE_NAME\
but not browse it at the FILESTREAM_DIRECTORY_NAME level - it in essence becomes a "hidden" directory that you must know the entire pathname to find (unless you guess it of course in a brute attack)
Other posters have dealt with the FILESTREAM set up.
To browse and access files within a filetable, VIEW DEFINTION and SELECT permissions will be required as a minimum. The ALTER permission referenced in dmc2005's post is not required.
Example (granting access to a Windows user or group):
GRANT VIEW DEFINITION,SELECT ON FileTableName TO [MYDOMAIN\MYGROUPNAME]
Assigning the User / Group to one of the fixed database roles (for example db_datareader) will not grant the required permissions for filestream access. The permissions must be explicitly granted.

Cannot attach database SQL Server 2012 error 5

When I type this:
CREATE DATABASE AdventureWorks2012
ON (FILENAME = 'C:\Users\sohm\Desktop\Pohm\AdventureWorks2012_Data.mdf')
FOR ATTACH_REBUILD_LOG ;
I get this:
File activation failure. The physical file name
"C:\Users\sohm\Desktop\AdventureWorks2012_Data_log.ldf" may be incorrect.
Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5 (Access is denied.) while attempting to
open or create the physical file 'C:\adventuredb\AdventureWorks2012_Data_log.ldf'.
Msg 1813, Level 16, State 2, Line 1
Could not open new database 'AdventureWorks2012'. CREATE DATABASE is aborted.
I know it has to do with permissions. I have the administrator account. I have read a million posts but nothing has worked so far. Also when I try to change the folder containing the mdf file, to full control but it keeps reverting back to read-only.
You should run SSMS as an administrator.
Also it is possible that you might be running query as an 'sa' user(sql server authentication).
Try running the query with windows Authentication.
SHORT VERSION
For allowing MS SQL server 2012 to attach the database files you must grant full access to the mdf and ldf files to:
NT Service\MSSQLSERVER
Full Access
LONG VERSION
SQL Security has been updated a lot in 2012 handling of files.
http://technet.microsoft.com/en-us/library/ms189128.aspx
If you look at the existing attached databases and there security you will probably see that there only are 2 roles allowed with full access. MSSQLSERVER and Administrators, when attached SQL Removes all other roles from the files.
Trying to set the MSSQLSERVER from the fil security Permission will not work.
Looking at your services.msc overview you will in a default install see that NT Service\MSSQLSERVER also runs the SQL server servics.
The service account is not visible, the same issue as with IIS AppPools, a sub group has been created by the system and "hides" the accounts from auto discovery, probably to try and secure the accounts but in my view just obscures the setup.
Regards Jan
Open the SQL Server Management Stdio in Administrator mode(Right click -> Select Run as Administrator. If it asks for User name and password enter your Administrator user name password). Then select Windows Authentication click ok, and now try to attache it will attache without any error.
This has nothing to do with YOUR account. SQL Server is trying to write to that folder under the context of the service account that is running SQL Server. You can see who this is by going to the Services applet and seeing who the instance runs as (probably NT AUTHORITY\SYSTEM or whatever). You can override that or you can place your MDF files in the data folder, which SQL Server already has inherent access to, instead of placing them in this other location on your C:\ drive.
Another way to solve this is to change all the SQL Server services to Local System Account instead of services. Start -> Run ->Services.msc -> Scroll down to SQL Server, you should see five services that start with SQL Server. Right-Click, Properties, Log On, change to Local System Account. Repeat for all the rest of the SQL Server Services and restart them all.
Try This
Go to the folder where you have stored mdf file.
Select file -> Right click -> click on mdf give full permissions to file for logged in user Security.
If still issue persist and it might me because of corrupted transaction logs, you may use tool SQL Database Recovery Tool Repairs to repair your corrupted mdf file.
Figured it out. I went to sql server configuration manager and right clicked SQL Server Service. Then I added my Windows Admin account to run the service and now it works.

Error when trying to create subscriptions in reporting services

I am trying to set up reporting emailing SQL Server 2005 Reporting Services. When I click to save a subscription I recieve the following error:
An internal error occurred on the report server. See the error log for more details. (rsInternalError) Get Online Help The SELECT permission was denied on the object 'sysservers', database 'mssqlsystemresource', schema 'sys'.
I was under the impression Reporting Services uses the role RSExecRole which is created during installation. Isn't mssqlsystemresources something that is not supposed to, and not easily touched?
This is most because the user doesn't have permissions setup correctly. Can you check if RSEXECROLE doesn't have any DENY permissions and has correct permissions on the reportserver db.
http://www.sqlservercentral.com/blogs/brian_kelley/archive/2007/11/6/3195.aspx
Based on the code in the above url, RSEXECROLE should have 323 rows on SQL Server 2005 SP3. Yours should match that.
Let me know what you find.