Forum Discussion

Million_queries's avatar
Million_queries
Copper Contributor
Dec 13, 2021

Invoke-sqlcmd throws login failed error

Hello,
I am not able to figure out why invoke-sqlcmd is not working. It’s giving login failed error..
When the azure release pipeline runs, if the database does not exist then it restores the new database from the .bak file....and i am using invoke-sqlcmd command for that......when i try to run the select statement it works but while doing the restore it does not seem to work and i cannot figure out why.....
The error is below -:
“Invoke-sqlcmd - cannot open database requested by login. The login failed”

I googled the error but nothing seems to be working.
Any help will be appreciated. Thanks
  • Million_queries's avatar
    Million_queries
    Copper Contributor
    I was able to resolve this issue. I was calling the database name in the invoke-sqlcmd which it did not like. Somebody replied in another forum and it resolved my issue. below command solved my problem invoke-sqlcmd -ServerInstance $server -Database master -Username $sqlusername -Password $sqlpassword -Query $sql Earlier i was using $dbname instead of master

Resources