SQL Server PowerShell dir - sql-server

I started to learn PowerShell. When I run
PS SQLSERVER:\sql> dir
I got this error:
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'DESKTOP-EGEQJFS' failed with the following error:
An exception occurred in SMO while trying to manage a service.
Failed to retrieve data for this request.
Invalid class
Any ideas?

It looks like you're using the SQL Server version of PowerShell. This is intended for performing advanced administration tasks with SQL Server and is not intended as a learning environment.
You're getting the "WARNING: Could not obtain SQL Server Service information" error message because the computer you're attempting to run the SQL Server PowerShell on does not have SQL Server installed or your Windows User account does not have permission to access the SQL Server's configuration data using WMI. If you have SSMS (SQL Server Management Studio) or SSDT (SQL Server Development Tools) installed you won't necessarily have SQL Server installed.
If you want to learn how to use PowerShell then use the Windows PowerShell, not the SQL Server PowerShell. You can find the Windows PowerShell under Start Menu > Windows PowerShell > Windows PowerShell. I recommend using the "PowerShell ISE" tool because it provides a GUI with a listing of all loaded Cmdlets.

Related

Unable to connect to master or target server

My .NET Database project currently deploys to SQL Server 2012.
We are moving to AWS and the SQL Server there is SQL Server 2019.
The AWS database uses Compatibility level of SQL Server 2012.
When publishing myApp_DEV.publish.xml from Visual Studio, it was successful.
It changes the AWS database correctly.
But, when I use CI/CD pipeline, it first got this error:
& "D:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe" "/SourceFile:D:\myAppFolder\Chocolatey\lib\myApp_db\bin\Debug\myApp.dacpac" "/Profile:D:\Apps01\Chocolatey\lib\myApp_db\bin\myApp_DEV.publish.xml" "/Action:Publish
*** Could not deploy package. Unable to connect to master or target server 'myApp'. You must have a user with the same password in master or target server 'myApp'.
So, I went to project property > Project Settings and changed the Target Platform from SQL Server 2012 to SQL Server 2019.
But now I got this error
& "D:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe" "/SourceFile:D:\Apps01\Chocolatey\lib\myApp_db\bin\Debug\myApp.dacpac" "/Profile:D:\Apps01\Chocolatey\lib\myApp_db\bin\myApp_DEV.publish.xml" "/Action:Publish
*** Could not deploy package. Internal Error. The database platform service with type Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider is not valid. You must make sure the service is loaded, or you must provide the full type name of a valid database platform service.
Is there anything else that I need to change the in the database project so that I can deploy it to AWS server using CI/CD pipeline ?
Thank you

Exporting SSIS project from SQL Server catalog

I am trying to export an SSIS project from the Integration Services Catalog and am getting an error:
The operation cannot be started by an account that uses SQL Server Authentication. Start the operation with an account that uses Windows Authentication. (Microsoft SQL Server, Error: 27123)
I am connected to SQL Server using SQL Authentication and the sys admin account. I don't have a login with which to use Windows Authentication. How can I export the project and packages to my local drive?
Right Way
You can use DTUtil Utility to perform these operation.
You can found helpful information at the following Links:
Script To Export All DTS Packages ON IS To File System
http://www.bimonkey.com/2010/01/ssis-command-line-utilities-part-1-dtutil/
Workaround
I know this is not the right way, this is a workaround:
Open a new Integration services project in visual studio
On the solution explorer tab add an existing package from sql server using your sql authentication

Remote Procedure call failed with sql server 2008 R2

I am working with SQL Server 2008 R2. I am unable to connect to my database remotely. I got the following error.
A network-related or instance-specific error occurred while establishing a connection
to SQL Server. The server was not found or was not accessible. Verify that the instance
name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I have checked the SQL Server properties and I enable the Allow remote connections.
I have checked the Service manager and SQL Server service are running.
I have checked the configuration manager, I can't see any services under SQL Server Services
and it shows Remote Procedure call failed
So please guide me.
Open Control Panel > Administrative Tools > Services > Select Standard services tab (under the bottom) > Find start SQL Server Agent
Right Click and select properties,
Startup Type : Automatic,
Apply, Ok.
Done.
I just had the same issue and was able to solve it by installing Service Pack 1.
This error occurs only after I have installed the Microsoft Visual Studio 2012 setup in my work machine.
Since it is being a WMI error, I recompiled the MOF file –> mofcomp.exe "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof"
I also un-registered and re-registered the sql provider DLL –> regsvr32 "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmprovider.dll" but issue not resolved.
Solution:
I have applied SQL Server 2008 R2 SP2 on my SQL 2008 R2 instance and that fixed the issue with Sql Server Configuration Manager. You can download setup from here... http://www.microsoft.com/en-us/download/details.aspx?id=30437 .
After trying everything between Stackoverflow and Google, I finally found a solution : http://blogs.lessthandot.com/index.php/datamgmt/dbadmin/remote-procedure-call-failed/
TL;DR :
If you are (or were) running multiple versions of SQL Server on your machine, that Configuration Manager shortcut on your start menu might be pointing to an older version, which it shouldn't be. It was pointing to an old Sql Server 2008 instance in my case.
The solution was to :
Go to either C:\Windows\SysWOW64 or C:\Windows\System32, depending on your system.
Look for an executable called SQLServerManagerXX.msc, and run the latest version if you have multiple ones. In my case, I had both SQLServerManager11.msc and SQLServerManager10.msc, where the 10th gave the error, and the 11th worked perfectly.
I can't comment yet, but make sure you made all the checks in this quide: How to enable remote connections in SQL Server 2008? It should work fine if all steps are made.
Upgrade your SQL Server to SP3
You can install it from:
http://www.microsoft.com/en-us/download/details.aspx?id=27594
This error appears to happen when .mof files (Managed Object Format (MOF)) don’t get installed and registered correctly during set-up. To resolve this issue, I executed the following mofcomp command in command prompt to re-register the *.mof files:
mofcomp.exe "C:\Program Files (x86)\Microsoft SQL Server\100\Shared\sqlmgmproviderxpsp2up.mof"
This one worked for me
start SQL Server Agent from the command prompt using:
SQLAGENT90 -C -V>C:\SQLAGENT.OUT
You might need to install SQL Server 2008 SP3.
SQL Server 2008 Service Pack 3
SQL Server 2012 Configuration Manager WMI Error – Remote Procedure call failed [0x800706be]
I got the samilar issue, while both SQLServer and SQLServerAgent services are running. The error is fixed by a restart of services.
Server Manager > Service >
SQL Server > Stop
SQL Server > Start
SQL Server Agent > Start
Open Control Panel
Administrative Tools
Services
Select Extended services tab
Find SQL Server(MSSQLSERVER) & SQL Server(SQLEXPRESS)
Stop these services and Start again (from the start & stop button displayed above)
Done.

sqlcmd not working after installing sql server 2005 express

I downloaded the 53.5 MB setup of SQL Server 2005 Express from this URL:
Microsoft SQL Server 2005 Express Edition
Then I ran sqlcmd by going into command promp , but it shows error
HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server 2.
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred
while establishing a connection to the server. When connecting to SQL Server 2005,
this failure may be caused by the fact that under the default settings SQL Server
does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.
Then I downloaded and installed Sql Command Line Utility from this URL:
Feature Pack for Microsoft SQL Server 2005 - November 2005
Then also it shows the same error.
Then I installed Sql Native Client, then also it didn't work. But when I installed Management Studio, then from Management Studio the connection is established, but not from sqlcmd from Command Prompt.
Please help.
"Just typing sqlcmd on its own won't work - how should the utility know what server to connect, what database to use, and what command to run??"
Funny thing. As I read the Microsoft documentation, just typing sqlcmd while sitting on the server should open a connection to this server. At least it can, depending on settings for security. Typing sqlcmd without any options for login/security may very well fail, but the utility will defintely try.
And SQLCMD without quit is just that, right?
What if you do something like:
sqlcmd -S W\SQLEXPRESS -E -d master -q "select * from sys.tables"
Just typing sqlcmd on its own won't work - how should the utility know what server to connect, what database to use, and what command to run??
You need to tell sqlcmd what you want to do! Get a list of its command options using sqlcmd -?, study them, and use them! Or read the MSDN docs on Using the sqlcmd utility with SQL Server Express - btw: searching MSDN for answers and documentation would be a good idea for all your SQL Server problems......
The SQL Native Client is definitely needed, yes - not sure what you mean by the second package there.

Check if SQL Server Agent is running from code?

How can I determine from code, if SQL Server Agent is running - using SMO?
I would think there was a property on the JobServer class, but I can't find anything.
Powershell is not an option.
Check if windows service (SQL Server Agent) is running...

Resources