Tuesday 15 June 2010

sql server - Error starting MSSQL as a different user via powershell -



sql server - Error starting MSSQL as a different user via powershell -

there's database @ work need often, need run mssql2005 different windows business relationship it. got tired of looking password, right clicking shortcut , telling run different user, made powershell script start mssql required user. starts programme , shows tables in db, when open table or seek run query, errors out following:

"microsoft sql server management studio - scheme cannot find file specified. (sqleditors)"

if normal way (right click shortcut , run different user), works fine. issue when open powershell script.

i've found powershell script works when business relationship logged onto node, sec logs off dies again. thing noticed first time loaded mssql powershell script, asked db name though saved recent connection via working way. it's it's not finding right configs or something... i've used exact script in real projects in past it's known work, i'm assuming problem has mssql2005.

the script:

function get-scriptdirectory { $invocation = (get-variable myinvocation -scope 1).value; if($invocation.psscriptroot) { $invocation.psscriptroot; } elseif($invocation.mycommand.path) { split-path $invocation.mycommand.path } else { $invocation.invocationname.substring(0,$invocation.invocationname.lastindexof("\")); } } $curdir = get-scriptdirectory $encpwd = get-content $curdir\password.bin $passwd = convertto-securestring $encpwd $exeloc = "d:\program files\microsoft sql server (x86)\90\tools\binn\vsshell\common7\ide\sqlwb.exe" $cred = new-object system.management.automation.pscredential '[username]' , $passwd start-process $exeloc -cred $cred

edit: svein fidjestøl's comment fixed issue. start-process needed "-loaduserprofile" @ end of it.

a lot of windows applications , services have implicit requirement user profile must loaded. seems case sql server 2005.

in powershell, load user profile when invoking process, pass -loaduserprofile parameter start-process cmdlet. in example, invoke sql server this

start-process $exeloc -cred $cred -loaduserprofile

sql-server powershell

No comments:

Post a Comment