Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The SQL server object created by this cmdlet uses the wrong credentials #9459

Open
andreiv3103 opened this issue Sep 1, 2024 · 4 comments
Open
Labels
bugs life triage required New issue that has not been reviewed by maintainers

Comments

@andreiv3103
Copy link

andreiv3103 commented Sep 1, 2024

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

In a script, running as LOCAL SYSTEM account, I am creating an SQL server object using this code:

            ## Create the SQL connection.
            $CmdletParams = @{
                SqlInstance            = 'sqlserver01'
                SqlCredential          = $ServiceCredentials
                TrustServerCertificate = $true
            }
            $SqlConnection = Connect-DbaInstance @CmdletParams

After that, I use the object in the Invoke-DbaQuery cmdlet:

            $CmdletParams = @{
                SqlInstance = $SqlConnection
                Database    = 'DatabaseName'
                Query       = 'TRUNCATE TABLE Table_Name'
            }
            Invoke-DbaQuery @CmdletParams

But, in the logs, I get the following error:

Screenshot 2024-09-01 135451

Looks like both cmdlets try to connect using the machine account (which is associated with the SYSTEM account) instead of using the credentials defined in the $SqlConnection = Connect-DbaInstance @CmdletParams. Why is that happening?

Steps to Reproduce

Steps to repro provided above.

Please confirm that you are running the most recent version of dbatools

I confirm.

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

5.1

SQL Server Edition and Build number

Unknown

.NET Framework Version

PSChildName Version


v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.09032
Full 4.8.09032
Client 4.0.0.0

@andreiv3103 andreiv3103 added bugs life triage required New issue that has not been reviewed by maintainers labels Sep 1, 2024
@andreiv3103
Copy link
Author

I added the credentials to each cmdlet and now both are working fine. I think my assumption that the SQL object will also contain the credentials was wrong.

@andreiv3103 andreiv3103 reopened this Sep 2, 2024
@andreiv3103
Copy link
Author

andreiv3103 commented Sep 2, 2024

Unfortunately, after adding the credential directly into the cmdlet, I still get the same error.
I don't really know how it worked the first time...
But now I have the same error in the logs as the one posted above. And the code looks like this:
image

@jebbster88
Copy link

Just wanted to confirm I'm seeing the same issue on 2.1.23

@jebbster88
Copy link

FYI I can it to work if I add "-NonPooledConnection" to the connect-dbainstance cmdlet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugs life triage required New issue that has not been reviewed by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants