Unit test on local SQL Server not possible due to login fail - sql-server

I am trying to run unit tests in Visual Studio on a local database. The unit test project was created by another user locally on his PC and runs there successfully. I cloned his project on my machine, created the database with the same publish profile as him but when I run the tests it fails with the error:
System.Data.SqlClient.SqlException: Login failed for user 'sa'..
I made sure that the unit test project in VS can access on the database by configuring the SQL Server Test Configuration. It means it should have access to my database. For both databases we use the same user name and the same password.

Related

Azure DevOps Pipeline Azure SQL Deploy won't work with SQL script (Failed to login)

I've been trying to deploy a database via a pipeline from Azure DevOps to an Azure resource group.
I have an ARM template for my database server in my Repo along with my DACPAC file.
In my release pipeline I first deploy the database server with an admin user defined in the ARM template to my resource group.
Then I use the "Azure SQL DacpacTask" to deploy the database schema. Here I give the admin credentials and it works flawlessly.
The issue is that the customer doesn't want it deployed as a DACPAC but rather an SQL script. They've given me a "CREATE TO..."-script from their database, created inside MS SQL Studio, which is also in my Repo.
The "Azure SQL DacpacTask" inside my release pipeline has an option for using an SQL file instead of DACPAC, but it doesn't work for me.
But no matter how I do it, my pipeline fails when running the "Azure SQL DacpacTask" and all I get, even in debug-mode is "Login failed for user '***'".
I can connect to the SQL Server through MSSQL Studio on my local machine using the admin credentials defined in my ARM template.
I've tried by adding the agent's IP before running the SQL script, but with no success.
Can anyone point me in the right direction or maybe tell me what I'm doing wrong? Why is it that it keeps failing to log in?
They want it deployed with little to no human interaction. Is it doable only through the ADO pipeline?
EDIT
Additional info:
I have tried with hardcoded password and user with no luck.
If I manually create a database and then try to deploy one via script and pipeline, it fails because a database already exists, and not because of a failed login.
I've setup Audit in Azure which generates 2 files with little to no info. I'm not sure what I'm looking at.

Azure Devops deploying web app to a server - how to also update database

We have a web app which due to budgetary reasons is running on a windows VM (IIS) with its database also running in SQL Server on the same server.
We have a build pipeline set up in Azure Devops which builds the web app and then creates an idempotent SQL migration file (We use Entity Framework), both the compiled app and the SQL file are copied into the build artefact.
We then have a release pipeline which deploys the web app into IIS on the server.
What I cant figure out is how to get the SQL file run into the database.
I have tried the "SQL Database Deploy" task but that seems to only want a .dacpac file, or the path of a SQL file which is already on the server - I dont seem to be able to give it a file that exists on the build machine to execute remotely.
I know that because we are using EF I could just make the application do its migrations on startup but that means that the app needs to run as a user with schema privileges which we don't really want, currently the app is only a data reader/writer.
Is there some mechanism that I can take the SQL script from the build artefact and run it on the remote VM? If not, what are my options for getting the file onto the VM so that I can run it using the "SQL Database Deploy" task? I don't want to deploy it with the web app as although its a small risk we don't want it lingering in a public folder.
Any help appreciated.

Active Directory Authentication Error for SQL Server SSDT Unit Tests

I am using a SSDT unit test project to test procedures on an Azure SQL Server. When I choose SQL Server authentication with a generic login for my server, I can connect no problems. However, when I choose Active Directory Interactive Authentication (the only AAD option available within my organisation and how I normally log in using Visual Studio or SSMS) and I try to run the unit tests, the test window shows the error 'System.ArgumentException: Cannot find an authentication provider for 'ActiveDirectoryInteractive'. Does anyone know how to fix this?
The connection string within my app.config is unchanged from the defaults provided to me.
ConnectionString="Data Source=[myserver].database.windows.net;
Initial Catalog=[myDatabase];
Persist Security Info=False;
User ID=[myEmail];
Pooling=False;
MultipleActiveResultSets=False;
Connect Timeout=60;
Encrypt=True;
TrustServerCertificate=False;
Authentication="Active Directory Interactive""

SQL Project in VSTS Continuous Integration via WinRM

Here is my solution.
I have a DB project in it, which multiple publish profiles. When I run publish from Visual Studio Manually by loading any profile it works perfectly.
We have our IIS in Azure VM and SQL in another Azure VM
We have a Continuous builds setup on Visual Studio Team Services, which will deploy site to Azure VM.
To the same build definition, I added a WinRm - SQL Server DB Deployment
Here is my Buil defination for dacpac step
When I run my build I get the following error
Microsoft.PowerShell.Commands.WriteErrorException: Deployment on one
or more machines failed. System.Exception: Invalid Publish Profile [
xxxxxxx ] provided
I don't really find any references on how to give profile information and why is it failing. Any help would be greatly appreciated.
Update
In order to resolve this as per #Jason Ye - MSFT suggestion, I copied my publish profile to Azure SQL VM and copied its full path and updated the profile path in build definition.
Then I got stuck with the following issue
Microsoft.PowerShell.Commands.WriteErrorException: Deployment on one
or more machines failed. System.Exception: Publishing to database
'DbName' on server 'xxxxxx.eastus.cloudapp.azure.com'. * Could
not load package from '/*.dacpac'. Illegal characters in path.
Since dacpac will keep changing, I cannot copy it to server before. How to get the path.

Error from SQL Server when run app without admin privileges

I have an app written in Delphi (it is not my app). When it starts, it is connecting to SQL Server instance (for example on localhost). If I run app with admin privileges everything is ok, but if I run it without - there is an error: SQL Server Connection Terminated.
App uses one dll file.
How can I figure out what is wrong or what needs admin privileges?

Resources