PowerShell script scenarios to connect to SQL Server with specific authentication scenarios
I'm trying to figure out I'm working on a personal project and I'm running into an scenario while trying to connect to a SQL Server instance from my PowerShell script. I'm using SQL Server 2019 with Windows authentication, and I've tried the following command to establish the connection: ```powershell $server = 'localhost'; $database = 'myDatabase'; $connectionString = "Server=$server;Database=$database;Integrated Security=True;"; $connection = New-Object System.Data.SqlClient.SqlConnection($connectionString); $connection.Open(); ``` However, I'm getting the following behavior message: ``` SqlException: Login failed for user 'DOMAIN\User'. ``` I've verified that the user has the correct permissions on the database, and I can connect to the same SQL Server instance using SQL Server Management Studio without any issues. To troubleshoot further, I tried using SQL authentication instead by modifying the connection string: ```powershell $connectionString = "Server=$server;Database=$database;User Id=myUser;Password=myPassword;"; ``` This also throws an behavior: ``` SqlException: Login failed for user 'myUser'. ``` I checked the SQL Server settings and confirmed that SQL Server authentication is enabled. I've also tried running the PowerShell script as an administrator and disabling any firewalls, but nothing seems to work. Is there a particular setting or configuration I might be missing that could cause these authentication issues? Any insights on how to successfully connect to my SQL Server from PowerShell would be greatly appreciated! This is part of a larger application I'm building. Any help would be greatly appreciated! I'm working on a service that needs to handle this. Is there a better approach? My team is using Powershell for this application.