0

In SQL Management Studio there is an option to start PowerShell via right-click on a database (for example).

However, I cannot run queries from that PowerShell session because, it claims, the login fails for my (domain) account.

I am logged in with the same account in Management Studio and started PowerShell from the Management Studio. How can I use the PowerShell session to do anything in SQL Server?

Command I tried was

invoke-sqlcmd "use sometable"

PowerShell then announced that it is using the "provider context" and deduces the SQL server name correctly. But then the query fails because "login failed for user 'mydomain\myaccount'".

What am I doing wrong?

2
  • Are you logged in to that specific instance of sqlserver with Windows authentication?
    – mattypenny
    Oct 25, 2012 at 11:06
  • Yes. I started PowerShell from within SQL Management Studio by right-clicking on a database I could see/select from/update. In fact the error message specifically mentions my account which I am using. Oct 25, 2012 at 14:59

1 Answer 1

-1

Do you have a database named "sometable"? The USE statement defines database context.

Try this:

Invoke-SqlCmd "select top 1 name from sys.tables"
1
  • The problem is the "login failed" message, not the contents of the command. I have a database called "sometable". But that's not the point. If I tried your example, I still wouldn't be logged in. Queries only work when the user is logged in. Oct 24, 2012 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .