What do I need to execute a SQL Server PowerShell module - sql-server

I am creating an Octopus deploy that installs a windows service on a remote server. I am re-using a template from a web deploy project that sets up the web services and web application (on other servers). It has an extra step that deploys database scripts to update the schema and stored procedures etc. This step is executed on the web server using SQL Server PowerShell tools (apparently).
I need to incorporate that as well into my project. The folks who set up the original project are long gone! I have managed to get it working up to the last step, however the SQL Server PowerShell tools needed on the new server are not available.
The database script step is throwing the following error.
Import-Module : The specified module 'C:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS' was not loaded because no valid module file was found in any module directory.
At C:\Octopus\Work\20160930164655-24\.ps1:1 char:14
The necessary folders and files exist on the web server. It looks like SQL Server Client is not installed though (judging by the start menu; I don't see SQL Server Management Studio for example).
In Programs and Features on the web server I see a bunch of SQL Server things:
Microsoft SQL Server 2012 Command Line Utilities
Microsoft SQL Server 2012 Data tier App Framework
Microsoft SQL Server 2012 Express LocalDB
Microsoft SQL Server 2012 Management Objects
Microsoft SQL Server 2012 Management Objects (x64)
Microsoft SQL Server 2012 Native Client
Microsoft SQL Server 2012 Transact-SQL Compiler Service
Microsoft SQL Server 2012 Transact-SQL ScriptDom
Microsoft SQL Server 2012 Transact-SQL Language service
Microsoft SQL Server 2012 TSQL Language service
Microsoft SQL Server Comnpact 4.0 SP1 x64 ENU
Microsoft SQL Server Data Tools - enu(11.1.20627.00)
Microsoft SQL Server Data Tools - Build Utilities - enu (11.1.20627.00)
Microsoft SQL Server System CLR Types
Microsoft SQL Server System CLR Types (x64)
Microsoft SQL Server System CLR Types for SQL Server 2012
Microsoft SQL Server System CLR Types for SQL Server 2012 (x64)
Windows Powershell Extensions for SQL Server 2012
I need to raise an IT ticket to get this set up on my new server but don't know what to ask for! What installation(s) would give me the above features? Or what install would allow me to execute that script?
Would the SQL Server Client 2012 suffice?
Note: the server I need to install on is 32 bit.

SQLPS is auto installed in sql server 2012. The old versions need to install it from download Featurpack.
It's installed normally for sql server 2012 in the folder:
c:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS
If it's not available in that path require installing:
Microsoft Windows PowerShell Extensions for Microsoft SQL Server 2012
It's availabl at url:
32 bit:
64 bit:
in Poweshell 3 you can run the command (without path):
Import-Module Sqlps -DisableNameChecking;
and it's valid if you use the path
Invoke-Sqlcmd is similar to the command line tool sqlcmd
You can run your script file using the command:
sqlcmd -S <server> -U <user> -P <password> -i <qry.sql>

What you seek is the Microsoft SQL Server 2012 Feature Pack, available here:
https://www.microsoft.com/en-us/download/details.aspx?id=29065
If you expand the "Install Instructions" section, and then scroll about halfway down the page, you will see that one of the components listed there is the PowerShell Extensions, which contains the SQLPS module. Note that this component depends on the Shared Management Objects component (also on the same page), which in turn depends on CLR Types (also on the page, but at least that one is already installed on your server).
There are different versions available for other versions of SQL Server:
SQL Server 2014: https://www.microsoft.com/en-us/download/details.aspx?id=42295
SQL Server 2016: https://www.microsoft.com/en-us/download/details.aspx?id=52676

Related

Connect to SQL Server Management Studio Express FAIL

I have Visual Studio 2010 Pro on a 32 bit Windows 7 machine.
Am trying to work through a DB tutorial requiring Micorosoft SQL Server Management Studio Express so
I Installed SQL Server 2005 Express (the 32 bit flavor)
However I can't even connect to the server
For server names I've tried OSR2-PC as indicated by my command line windows >hostname response
I then tried .\sqlexpress per various blog recommendations (see pic)
I get an error popup that says:
"Additional information:
-> This version of Microsoft SQL Server Management Studio Express can only be used to connect to SQL Server 2000 and SQL Server 2005 servers "
Would greatly appreciate help.
Check the SQL services that are running by executing services.msc. Installed SQL Server instances will be shown along with the instance name. Sometimes the instance name is not the same as the hostname.

Supporting SQL Server Management objects for both SQL Server 2008 R2 and 2012 in Winforms

I have a Windows forms application targeting .NET 4.5. The application provides functionality for programmatic database backup and restore using SQL Server Management objects (SMO).
The application should support Express editions of both SQL Server 2008 R2 and SQL Server 2012 as its using only features that are supported in both versions.
Now the SMO assemblies (Microsoft.SqlServer.ConnectionInfo, Microsoft.SqlServer.Smo, Microsoft.SqlServer.SmoExtended etc.) to reference in the project will be in different folders depending on the version of SQL Server the client has installed
SQL Server Express 2008 R2: C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies
SQL Server Express 2012: C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies
As you can see, when the client is running 2008 R2, the assemblies will be down the 100\SDK folder while for those that want to run SQL Server 2012, they will be in the 110\SDK folder.
So if I reference the 100\SDK folder, the application will break for clients running SQL Server 2012 because they will only have the 110\SDK folder.
So how is such a scenario normally handled?
If you want to develop an application that uses SQL Server Management Objects (SMO), you should select the Client Tools SDK when you install SQL Server.
To install the Client Tooks SDK without installing SQL Server, install Shared Management Objects from the SQL Server feature pack.
If you want to ensure that SQL Server Management Objects is installed on a computer that will run your application, you can use the Shared Management Objects .msi in the SQL Server feature pack.
Source: Installing SMO - SQL Server 2012
Going by the underlined paragraph, I guess I can always install a common Shared management objects msi across client machines irrespective of sql server version being run.

How to run SQL Server 2012 Services

I have Installed Microsoft Visual Studio 2012 (Ultimate) , and it installed all the SQL files,
yet I can't find the SQL Server Manager in the Start Menu, like the old version, so I can't start the services, , or there is an other way to run the services, so I can connect to the SQL Server?
In Run window, type "C:\Windows\SysWOW64\mmc.exe" /32 C:\windows\SysWOW64\SQLServerManager12.msc. I did come across the same problem (Sql Server Configuration Manager is not in start menu) before, and I had to pin it to task bar.
SQL Sever 2012 service are installed via Microsoft® SQL Server® 2012 Express as VS 2012 does not install it unless you are using custom installer..
Once you install Microsoft® SQL Server® 2012 Express in your machine you can use SSMS and other tools to manage SQL services on your machine.
Use 'sqlserver.exe' to start SQL Server from the command line - MSDN reference here. Or you can download SQL Server Management studio as shown below - from this link.

32bit OSQL issue with 64bit Windows+64bit SQL Server

I have a Windows 2008 x64 server and with SQL Server 2008 x64 installed. osql.exe under SQL Server directory could list instances with -L. I copied osql.exe+osql.rll from another SQL Server 2005 x86 and '.\osql.exe -L' returns error like "[ODBC Driver Manager] Data source name not found and no default driver specified".
After check registry 'HKLM\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI', the 'SQL Server' and 'SQL Server Native Client 10.0' are ok and related dll files are ok. I also checked MDAC version, it's 6.0.6002.18005. Did i miss anything?
One interesting thing is osql.exe from SQL Server 2000 ran well to list instances on the server. And osql.rll isn't necessary, the osql.exe only needs msvcr71.dll.
What can i do to make osql.exe(from sql 2005) to run on the server? And are there any difference between those 2 osql.exe(sql 2005, sql 2000)?
As DaveShaw said, you should probably be using SQLCMD.EXE instead... fortunately the syntax is quite comparable to the old OSQL.EXE, so the transition shouldn't be hard.
You can download SQLCMD (a/k/a the Microsoft SQL Server 2005 Command Line Query Utility) from the latest Feature Pack for SQL Server 2005 page. Install the appropriate SQLCMD and the SQL Server Native Client (also on the same page) and you can run the commands from any client system on the network, x86 or x64 no matter.

SQL Server version 612 , 655?

I have SQL Server 2008 and VS2008 installed on my computer and I am trying to run a web application I've created on a computer which has SQL Server 2008 and VS2008 and VS2010 beta 2 with its SQL Server Express.
I am getting an error with the database version that is
"...aspnetdb.mdf" cannot be opened because it is version 655. This server supports version 612 and earlier...."
Configuring the database in Visual Studio ->Tools -> Options -> Design-Time Validation Database is not working since I don't have the SQL Server version comes with VS 2010.
EDITED : I also edited aspnetdb and inserted a few more tables so I need the same aspnetdb
Is there any solution to convert this db ?
Also, after fixing this, I am looking forward to upload it on my hosting which has SQL Server 2005 DB and configure it in PLESK.
The SQL Server databases have a version specific format. Each SQL Server runtime version (SQL 2008 SP1, SQL 2008 RTM, SQL 2005 SP2, SQL 2005 SP1, SQL 2005 RTM etc) knows how to upgrade to its own verison. Unfortunately, once upgraded the database cannot be downgraded. So if your MDF was upgraded to version 655, it cannot be downgraded to any prior version. If you know you're going to deploy on SQL Server 2005, you must develop on SQL Server 2005 too. Not only that, but the actual build number of your development has to match the build number of the deployment (or at least be lower than that): the SP level and CU level must match.
You can a attach the 2008 version MDF you created to a SQL Server 2008, script out the database content, then import the script into a SQL Server 2005 database of the proper version.
I had this problem and when I changed my_computer_name\SQLEXPRESS with . to connect to server and it works and I could attach MDF file
may be you have both services run. (Mssql2008 and mssqlexpress) Maybe you have runing the mssqlespress running, that's the error that you have. Try to stop the mssqlserver express service and run mssql2008 services, and attach again your databases. I try this and works for me

Resources