FileStream doesn't seem to get enabled - sql-server

On one of our Dev DBs I am trying to enable FileStream.
I ran the script below and it is says it went from 0 - Disabled to 2 - Enabled:
Use FileStreamTest
GO
EXEC sp_configure 'filestream access level', 2
GO
RECONFIGURE
GO
But When I run this I get the error FILESTREAM is disabled?:
ALTER DATABASE FileStreamTest
ADD FILEGROUP FS_FG_20110101
CONTAINS FILESTREAM
GO
Running this Shows a value of 2 (Enabled):
SELECT * FROM sys.configurations
WHERE name = 'filestream access level';
Error Message:
Msg 5591, Level 16, State 3, Line 1
FILESTREAM feature is disabled.
Any ideas what I am doing wrong?
EDIT:
Do I have to go into the SQL Server Configuration manager and change the properties on the MSSQLSERVER instance (service) as well?

Yes, you do need to enable file stream through SQL Server Configuration Manager. Here is some more information.

On SQL Server 2008 R2 it is necessary to restart the SQL server service after the reconfiguration even when you execute RECONFIGURE or RECONFIGURE WITH OVERRIDE.
Proof:
SELECT * FROM sys.configurations WHERE name = 'filestream access level';
returns the value for configuration setting 1580 "filestream access level" as 2 but value_in_use 1.
After a restart of the service, the problem goes away and there is one obstacle less on the winding road of FILESTREAM configuration.

Related

SQL Server OPENROWSET without SYSADMIN role

We extensively use the OPENROWSET function to import .CSV and Excel files into our SQL Server 2012 environment, using MSDASQL or ACE:
SELECT *
FROM OPENROWSET ('MSDASQL',
'DRIVER={MICROSOFT access TEXT DRIVER (*.TXT, *.CSV)};',
'SELECT * FROM E:\INCOMING\REPORT_EXTRACT.CSV')
Or using ACE:
SELECT * FROM OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','TEXT;DATABASE=E:\INCOMING\;HDR=YES;', 'SELECT * FROM [REPORT_EXTRACT.CSV]');
We're experiencing the classic error message:
Msg 7415, Level 16, State 1, Line 1
Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server.
The ONLY workaround to enable this, is granting said user(s) with the SYSADMIN role - obviously not ideal.
The location of the file(s) is on the server itself, for which the users accessing DO have the necessary permissions to access that file folder. The SQL Server service is running under the local system account with permission to interact with the desktop.
We've tried the following workarounds/fixes to no avail:
1 Executed the following code:
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’AllowInProcess’ , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’DynamicParameters’ , 1
GO
*2 The DisAllowAdHocAccess registry fix:
This is the current state:
3 Adding the ADMINISTER BULK OPERATIONS permission to the said users
We have dozens of expressions and files within our procedures that use OPENROWSET, therefore BULK INSERT, building SSIS packages, leverage Excel files as linked servers are NOT feasible options.
Any suggestions?
Wow - After YEARS of troubleshooting, I finally figured out what it was!
The registry entry value that controls the Allowing of Ad-hoc access, relies on the DisallowAdHocAccess being in that EXACT sentence case.
In our case, the "A" in AdHoc was not capitalized:
To fix this, I:
Deleted the registry value as described
Re-enabled the Disallow AdHoc Access option (Which re-created the registry value)
Manually set the Registry DisallowAdHocAccess value to "0"
Problem solved!

Could not import package. Warning SQL72012: The object exists in the target

I exported my Azure database using Tasks > Export Data-tier Application in to a .bacpac file. Recently when I tried to import it into my local database server (Tasks > Import Data-tier Application), I encountered this error:
Could not import package.
Warning SQL72012: The object [MyDatabase_Data] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Warning SQL72012: The object [MyDatabase_Log] exists in the target, but it will not be dropped even though you selected the 'Generate drop statements for objects that are in the target database but that are not in the source' check box.
Error SQL72014: .Net SqlClient Data Provider: Msg 12824, Level 16, State 1, Line 5 The sp_configure value 'contained database authentication' must be set to 1 in order to alter a contained database. You may need to use RECONFIGURE to set the value_in_use.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET CONTAINMENT = PARTIAL
WITH ROLLBACK IMMEDIATE;
END
Error SQL72014: .Net SqlClient Data Provider: Msg 5069, Level 16, State 1, Line 5 ALTER DATABASE statement failed.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET CONTAINMENT = PARTIAL
WITH ROLLBACK IMMEDIATE;
END
(Microsoft.SqlServer.Dac)
I followed the advice on other posts and tried to run this on SQL Azure database:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
However, it says
Could not find stored procedure 'sp_configure'.
I understand the equivalent statement in Azure is:
https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-scoped-configuration-transact-sql?view=sql-server-2017
What is the equivalent statement to "sp_configure 'contained database authentication', 1;"?
The solution is to execute this against the master database of your local/on-premise SQL Server:
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
Thank you to David Browne - Microsoft and Alberto Morillo for the quick solution.
I had the same issue and it got fixed by importing the bacpac via command prompt. In link Import Bacpac go to SQLPackage section and run the command provided there.
sqlpackage.exe /a:import /tcs:"Data Source=<serverName>.database.windows.net;Initial Catalog=<migratedDatabase>;User Id=<userId>;Password=<password>" /sf:AdventureWorks2008R2.bacpac /p:DatabaseEdition=Premium /p:DatabaseServiceObjective=P6
The solution that worked for me was to directly copy DB from azure to my localhost.
Create a new database in your local DB server.
Right-click on a new database, Tasks -> Import data.
Provide data for Azure db:
Provide data for your localhost:
Click Next. Check the first checkbox to select all.
On the next form choose -> Run immediately
Wait until the process is completed.
Using the Azure portal to Import a bacpac:
The Collation chosen in the first step of the Azure SQL Import wizard, is important!
It needs to match the Collation in the source DB that was used to create the bacpac.
The sqlpackage and SSMS methods do NOT need this step.

SQL Server 2012 Logon exception

I have 2 applications connecting to the same database, when starting each individually both are fine. When I start them in the same time one of them will get logon exceptions as you may see below, this happening in 99% of my tries (so very rarely they are fine together).
And it is always the same application that gets the exceptions (1):
an application that's doing queries over the database
an application that connects to the service broker (this one work in all cases)
The 1st app will crash if I delay the start of the 2nd.
Here are some sql server logs:
2015-09-18 07:27:20.43 Logon Error: 18456, Severity: 14, State: 38.
2015-09-18 07:27:20.43 Logon Login failed for user 'domain\user'. Reason: Failed to open the explicitly specified database 'dbname'. [CLIENT: <local machine>]
2015-09-18 07:27:21.32 spid55 Setting database option ENABLE_BROKER to ON for database 'dbname'.
In SQL Server logs it is always like that, 2 line Logon error and then the ENABLE_BROKER line. I'm thinking that the service broker has something to do with the previous 2.
Details about envirenmont: SQL Server 11.0.3153.0 - 64 bit, Windows 7 (7601) running on a VM.
Because your database is in single-user mode. With single-user mode, only one client can connect to the database.
Change it to mulptile-user mode
GO
ALTER DATABASE AdventureWorks2012
SET MULTI_USER;
You can read more for the single-user mode here: https://msdn.microsoft.com/en-us/library/ms345598.aspx?
Finally i found what was causing this, it was the below alter database statement for which I don't see it's usage for now (while using the service broker it should be enabled by the db admin and not each time when the app is restarted). After removing that code everything seems fine.
ALTER DATABASE [dbname] SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
Inherited code fun :-) (not)

SQL Server production server - all databases are in recovery pending state

All the databases in my SQL Server production server are in recovery pending state. I tried to execute different queries but they were of no use. Please help me as production work has been stopped at client side.
Tried to execute alter commands - but show error as following:
Msg 5120, Level 16, State 101, Line 1 Unable to open the physical file
"G:\Data\MSSQL\Database.mdf". Operating system error 3: "3(The system
cannot find the path specified.)". File activation failure. The
physical file name "G:\Data\MSSQL\Data\Database_log.ldf" may be
incorrect. Msg 945, Level 14, State 2, Line 1 Database 'Database'
cannot be opened due to inaccessible files or insufficient memory or
disk space. See the SQL Server errorlog for details
Msg 5069, Level 16, State 1, Line 1
Recovery pending means that for some reason SQL cannot run restart recovery on the database. Usually this is because the log is missing or corrupt.
Check to see if you can find the Database.mdf and Database_log.ldf files in the folder specified.
Check your system has not run out of disk space.
This could be caused by a hard drive failure. You may need to do a full restore of your last full back, any differentials and then restore the logs up until the log error occurred.
See similar issue here
My team encountered this error many times for my clients & I know, It is not easy to manage in the Production server. In your case Error 5120 –This error comes when the database is in Read Only Mode.
To fix this you can below code
USE [master]
GO
ALTER DATABASE [SQLAuthority] SET READ_WRITE WITH NO_WAIT
GO
After fixing 5120, you can process to fix "databases are in recovery pending state"
Recovery Pending – If the SQL Server knows that database recovery needs to be run but something is preventing it from starting, the Server marks the db in ‘Recovery Pending’ state. This is different from the SUSPECT state because it cannot be said that recovery is going to fail – it just hasn’t started yet.
Execute the following set of queries:
ALTER DATABASE [DBName] SET EMERGENCY; GO
ALTER DATABASE [DBName] set single_user GO
DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS; GO
ALTER DATABASE [DBName] set multi_user GO
Note: You can also read the Microsoft Warning on DBCC CHECKDB REPAIR ALLOW DATA LOSS.
It might be because of following possible causes:
Permissions
Find your SQL Server instance in the services list and double-click it, then select the Log On tab. It is this log on account that must have sufficient permissions to write to the temporary backup folder location. Check the permissions on the temporary backup folder by right-clicking it in Windows Explorer, selecting Properties, then navigating to the Security tab. Make sure that the account SQL Server is using has explicit read/write permissions for this folder.
Mapped Drives
Use a fully qualified UNC path instead of a mapped drive letter.
Lack Of Domain Trust
You can resolve this issue by ensuring that a trust between the two domains is established. You may also need to configure the SQL Server service account with pass-through authentication between the domains.
Please refer more here for recovery db
Execute these queries to fix SQL server database in recovery pending state:
ALTER DATABASE [DBName] SET EMERGENCY
GO
ALTER DATABASE [DBName] SET single_user
GO
DBCC CHECKDB ([DBName], REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS
GO
ALTER DATABASE [DBName] SET multi_user
GO
EMERGENCY mode marks the SQL Server database as READ_ONLY, deactivates logging, and gives the permission to system admin only. This method is capable of resolving any technical issue and bringing the database back to the accessible state. The database will automatically come out of the EMERGENCY mode.

MSSQL mirroring error 1499

I`ve got a problem with my mirroring. I have already uses this feature to make 2 db work.
But it was on test bases.
Now when I use my scripts on work DB it throws an error:
Msg 1499, Level 16, State 1, Line 1
Database mirroring error: status 1488, severity 16, state 1, string db_name.
Any suggestions?
you database may be in single user mode
right click the database -> options and select MULTI USER under restrict access
try to check the principal and mirror server names, dtabase name etc. It is possible that there is misprints.
This happened to us recently. We found that SQL set the restored database to single user mode during the restore process.
After some research, we simply restarted SQL server services on the mirror. When SQL started back up, the restored database was in multi-user mode and we were able to initialize mirroring without any issues.
There are other sites out there with answers as well, but they involve taking down the principle database. That was not really an option for us at the time. Here is one example in case restarting the mirror does not help the next person who runs into this.
http://blog.armgasys.com/?p=259
I had some what similar issue this is how I solved it. When I ran wizard for mirroring it created endpoints(first part) successfully but when i tried to turn on mirroring it gave me error.
So I solved it by running below command on both server
USE [master]
alter database [yourdatabase] set partner off;
go
--Secondary already had partner but primary did not
--- then i ran below commands on each server.
USE [master]
ALTER DATABASE [yourdatabase]
SET PARTNER = 'TCP://OtherMachineSQLname.domain.LOCAL:5022';
GO
-- then mirroring started to work.

Resources