Activate FileStream on SQL Server 2012 only with code (query) - sql-server-2012

I'm desperately trying to activate FileStream only with queries. By following the MSDN procedure everything is ok, but I would like to enable it without using SQL Server Configuration Manager or SQL Server Management Studio.
On several website I read that this query was enough to activate this feature (this query is done in the MSDN procedure but after some configuration in SQL Server Configuration Manager ) :
EXEC sp_configure 'filestream_access_level', 2;
GO
RECONFIGURE
GO
The message L option de configuration filestream access level est passée de 2 à 2. Pour installer, exécutez l'instruction RECONFIGURE." is gave but if I check the service's proprieties Filestream is steal disabled, even if I execute RECONFIGURE again. If I try to open a connection to a base featuring Filestream columns i get a message confirming Filestream is not enabled.
I also tried this query :
USE master
GO
EXEC sp_configure 'show advanced options'
GO
EXEC sp_configure filestream_access_level, 3
GO
EXEC sp_filestream_configure
#enable_level = 3
, #share_name = N'FS';
GO
RECONFIGURE WITH OVERRIDE
GO
Without succes, althougth the sp_filestream_configure seems to not exist.
This website tell the issue could be the default language of my server, but after change the default language to English nothing was better.
https://stackoverflow.com/questions/1...tream-access-l
I hope someone will be able to help me. Thanks. Sorry for my bad english, I'm french ;)

You have to do both. One is enabling the feature in the configuration manager. The other is setting the access level.
Here's the MSDN guide to walk through:
https://msdn.microsoft.com/en-us/library/cc645923.aspx
You're only doing step 11, you need to do the first 10 steps as well.

Related

How to copy table from Production to Development?

I am working on Development Server Named as SQLDEV01 and the db name is University and the table name is cse.students. During my work on table cse.students I lost some rows so I need to get the all the exact data from Production server.production Server Name is SQLPROD01.
How can I query to get the production data without using SSIS?
Setup a linked server from the development to production servers before doing the following from SSMS. All code should be executed on the development server.
http://technet.microsoft.com/en-us/library/ms188279.aspx
-- On Development server [SQLDEV01]
TRUNCATE TABLE [University].[cse].[students];
GO
-- Use link server to move data
INSERT INTO
[University].[cse].[students]
SELECT
*
FROM
[SQLPROD01].[University].[cse].[students]
GO
This assumes there are no identity columns on the target.
If you do have identity columns, turn on/off allow inserts before/after executing the above insert.
-- Before Insert, execute this statement
SET IDENTITY_INSERT [University].[cse].[students] ON
GO
-- After Insert, execute this statement
SET IDENTITY_INSERT [University].[cse].[students] OFF
GO
You can also create an ad-hoc connection using the OPENROWSET command.
http://technet.microsoft.com/en-us/library/ms190312.aspx
INSERT INTO
[University].[cse].[students]
SELECT
PRD.*
FROM
OPENROWSET('SQLNCLI', 'Server=SQLPROD01;Trusted_Connection=yes;',
'SELECT * FROM [University].[cse].[students]') AS PRD;
I did not check the syntax for your environment, please check.
If add hoc queries are set off (0), have the DBA turn them on (1) temporarily. Execute the following on the production server.
http://msdn.microsoft.com/en-us/library/ms187569.aspx
-- Show all settings
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
-- What is the current setting?
sp_configure
GO
-- Allow add hoc queries
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
If (s)he does not allow that, you are stuck with a physical linked server.
If you are using delegation - choice #3, you have to watch out for the double hop issue.
http://blogs.msdn.com/b/sql_protocols/archive/2006/08/10/694657.aspx
I would configure the linked server with a specific account on production that has rights to select the data. See choice #4.
There are a few ways to do this. One that is pretty much failsafe is the following:
In Microsoft SQL Management Studio expand the server node for the source server - Then expand the Databases node. Right click on the source database and select Tasks -> Generate Scripts. When the dialog pops up click next. Select the "Select specific database objects" radio button. Expand the Tables node as check the table you want to copy. Click the next button at the bottom. Click the advanced button. In the options that pop up for Script DROP and CREATE select Script DROP and CREATE on the right. For the option Type of data to script select schema and data on the right. Click OK. Now back on the main dialog you need to select "Save to Clipboard" or "Save to new query window". I usually select clipboard because I am usually going to a different server but select what works best for you. Click next. Click next again and the script will generate according to your selections. Now just run that script on the destination database.
please use this query generalized query by replacing your entries
select * into targetTable from [sourceserver].[sourcedatabase].[dbo].[sourceTable]

Read contents of a text file into a varchar WITHOUT using BULK

I've got a problem whereby I need to read data from a .txt file into a variable in SQL Server. The read needs to be performed programmatically, as it's going to form part of a stored procedure, and it needs not to utilise the BULK method, as I don't have permissions to use the BULK method on the database in question. Is this possible?
Thanks in advance :)
Can you get them to allow Ad Hoc Distributed Queries? Then you can use OpenRowset or OpenDatasource.
SELECT *
FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=c:\users\graham\desktop;',
'SELECT * FROM [data.txt];'
Here's the recofiguring code, if you need it:
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
go
This is a laborious technique, though -- you sure you can't use client code? Even, I dunno, VBA in Excel or something?
g.
There is no other way to read the contents of a file without these permissions in SQL Server, or without setting up a link to the file. Otherwise, you have to do this through SSIS or using programming.
The solution is to get the permissions to solve your issue.

Opening a batch file using SQL Server procedure

Opening a batch file using SQL Server procedure....
For this, I took the example of opening a notepad. And able to open it with the following code :
start "c:\windows\system32" notepad.exe
--- saved as : note.bat
I tried to open it with following procedure :
ALTER procedure [dbo].[executebat]
as
begin
EXEC master.dbo.xp_CMDShell 'D:\ducont\note.bat'
end
also I enabled the xp_cmdshell option with following code ::
-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
But when I try to execute the procedure, it showing continuously
" Query Executing..."
and no output !!
Guide me if I went wrong anywhere .
Simple answer. When you run xp_cmdshell it is creating a shell to do any work you ask it to. Your bat file is running inside that shell, and will open notepad, again inside the shell. You just won't be able to see it. Since it's expecting input (and can't get any) you are stuck with the " Query Executing..."
There really isn't a good way to do what you are asking for other than possibly using CLR. Unfortunately I don't know enough about it to say for certain one way or another. There may be an easier way in SQL 2012 or 2014 but I haven't seen it yet.

Easy Install Update stored procedure in sql server express 2005

We have a stored procedure that needs to be updated at a customer site. Basically we will be emailing the changed sp to customer. What is the easiest way a non tech user can install update this sp in sql server express 2005 ? I would ideally like to create some bat file or exe that the user can just double click and the sp gets installed. I know c#, t-sql and basic dos script commands. OS is win xp. Please do not propose any fancy solutions using powershell since that may not be installed on customer machine. Note this is sql EXPRESS 2005. The sp itself is like any standard sp that has below structure. Worst case I plan to create a word doc with step by step screenshots on how to open sql management studio , open file, execute....
use [dbname]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_name]')
AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_name]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_name]
AS blah blah
thank you
If the user has SQL Server Management Studio, then they also have SQLCMD which is a command line utility for connecting to the database. You could put your sql script in to a .sql file and then create a .bat file that calls SQLCMD with the appropriate command line switches.
You should be able to build a (C#) application with a new SqlCommand {type = text}, containing your update sp, and as long as the connection string info is correct, you should be able to build it, send it to them to run the exe, and then done.
The only difficulty I see is making sure the connection strings are right if you don't already know their environment and aren't working with a technical user.
Good luck!

Resolve hostnames with t-sql

How can i resolve a hostname in t-sql? a 2000 compatible method is preferred. Although something that works on 2005/2008 would also be helpful.
eg. If i have the hostname stackoverflow.com i want to return 69.59.196.211
Well, I suppose you could use xp_cmdshell to execute nslookup and parse the results. Seems like a really awkward thing for SQL Server to be doing, though.
exec master..xp_cmdshell 'nslookup intel.com'
.. then you'll probably want to stuff that in a temp table and walk through the results.
You could also, if you can get access to SQL Server 2005 or 2008, build a stored procedure or function in .NET and do a simple call to Dns.GetHostAddresses().
SQL Server may block access to procedure 'sys.xp_cmdshell' as part of the security configuration. As a system administrator you can enable the use of 'xp_cmdshell' as follows:
-- Allow advanced options.
EXEC sp_configure 'show advanced options', 1;
GO
-- Update the currently configured value for advanced options.
RECONFIGURE;
GO
-- Then, enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- Update the currently configured value for this feature.
RECONFIGURE;
GO
-- Then you can go ahead and run ...
exec master..xp_cmdshell 'nslookup microsoft.com'
GO