Sql Exception when connecting to Azure Mobile Service database - sql

I'm using .net backend for Azure mobile services. I've published the service on the cloud with the publishing profile downloaded from Azure portal.The service gets published successfully. But I'm unable to connect to the service with my windows phone client. I get 500 response from the service. The logs on the portal shows this error
"Exception=System.InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. ---> System.Data.SqlClient.SqlException: Login failed for user 'KqRUJJyDGlLogin'."
I'm using web.config transforms and in the Web.Release.config , the connectionstring with name , "MS_TableConnectionString" is pointing to the cloud db.
Is something that I'm missing over here.
Please help.
Thanks

It seems to be a problem with droping and recreating the db.
If you have something like this:
public class MyInitializer: DropCreateDatabaseIfModelChanges<MyContex>
in your WebApiConfig.cs change it to CreateDatabaseIfNotExists...
If you want to change your model, manually drop the tables of your db.
That might not be a perfect solution, but it works for me.

Related

Connection string for parameterized Linked Services - Azure SQL / Azure Synapse

I have a requirement where in I need to parameterize my Azure SQL/Azure Synapse linked service using 2 parameters 'DBServer' and 'DBName'. I configured my collaboration branch as below and everything works as expected in my Synapse workspace.
Even the linked service ARM template shows the connection string values as expected.
However when I publish the code (using the publish button in Synapse workspace), the code in the Synapse Live mode does not contain these parameters defined. Please see the snippet below.
Even the code in the TemplateParameter file of the publish branch is blank.
I tried removing the parameters and put in the actual values for Server and DBName, it still shows no values in the publish branch/Live mode. While I understand that the git mode does not store secrets, this case of mine does not have any secrets and I am authenticating via Managed Identity.
Is there a solution to deal with this scenario? I would not prefer to store the connection string in KeyVault and refer it back in the linked service as it does not make the solution completely dynamic.
I created Azure sql database and created synapse pool in Azure portal. I created SQL linked service in synapse pool with managed identity authentication.
to authenticate with managed identity, I created user in SQL database with synapse pool name using below query
create user [SynapsePoolName] from external provider;
ALTER ROLE db_owner ADD MEMBER [SynapsePoolName];
Image for reference:
Linked service:
I published the Linked Service with publish button.
Image for reference:
It published successfully.
When I open the linked service after publish, I am getting the parameters.
Image for reference:
I got the parameters in template also.
Image for reference:
It worked in my machine kindly check from your side.

Azure App Services cannot connect to Azure SQL Database

I have an API published to Azure App Services, using ef core, connect to Azure SQL database. below are the steps and the problem:
The Azure SQL database is up and running OK, I setup two firewall rules, one for my local dev ip, one for Azure App. I can connect to Azure SQL from local without any issue, and I have done the migrations.
I copied the connection string from Azure SQL and put in the appsettings.json, running the API from my local and connect to Azure SQL without any issue.
I published my API to Azure App services without any issues, I can see my app running OK since it has static file.
Then I went to Azure App Services => Settings/Configuration => Connection strings, create one new connect string with the same key/value as I used in the appsettings.json, based on the document from Microsoft: https://learn.microsoft.com/en-us/azure/app-service/containers/configure-language-dotnetcore#access-environment-variables
But the problem is after I done these, my API still not working, the api call to SQL return error 500.
Anything I missed or did wrong?
Thanks!
Thanks for the comments CSharpRocks, I did by adding the client ip, but I figured that's not the right way, so resolved by set the "Allow Azure services and resources to access this server" to True, that works.
For Others looking for the answer I had followed the steps above and it still did not work for me. But when I went to Visual Studios --> Publish --> Service Dependency's --> Add Azure SQL Database That fixed it for me.

Can't interact with database when published to azure

Below is the steps i have took to publish my Website to Azure. I have two data connections the "defaultconnection" for users tables log in register etc. The other is a connection to an Azure Sql Database.
On Azure i created a new app service.
In Visual Studio i click on project and select publish.
In the publish Web window that pops up i select Microsoft Azure Web Apps.
In the following window i select the app service i created in Azure.
In the settings window it shows the two connection database connections.
They both have the same connection string which is the Azure hosted Database. I am not sure what to change the connection string to for the users table. I created a SQL database in azure and connected that to the app service then used that connection string for the "defaultconnection". The string is below
Server=tcp:userauthen.database.windows.net,1433;Data Source=userauthen.database.windows.net;Initial Catalog=USERAUTH;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
I published to azure and am able to go through the pages but as soon as i try to interact with the database i get an internal server error 500.
I tried publishing the website without userlogin so i could see if it connected to the Azure sql database but i still get the internal server error 500. I am really stuck at this point and any assistance would be helpful.
So i changed the firewall settings to allow certain IP address and it worked. I can access both my databases.

Azure SQL database - login failed

I have two web apps in azure plus one SQL database. One of them connects to the db withouth any problem. However the other web app isn't able to connect. I get the error:
Login failed for user 'xxxxxx'.
This session has been assigned a tracing ID of 'a632c957-78dc-4f13-b07f-ff646b04895c'.
I already copied and pasted the connection string from the working web app to the other one with no luck.
Is there any configuration to maybe "allow connections" from a specific web app?
Thanks

SQL XML Bulk Loader - Error connecting

I'm using the sqlxmlbulkloadlib to perform an xml bulk load. When integrated security=SSPI, the process completes fine inside a workflow hosted on my local machine in a wcf service. However, when that workflow is hosted on our server and kicked off from a service reference on an aspx page, the bulkloader produces an error connecting to the data source. I have tried using sql server authentication instead, but that fails even on my local machine with the same error connecting to data source.
My connection string looks like:
"provider=SQLOLEDB;data source=Myserver;database=Mydb;User ID=Myuser;Password=Mypassword"
Ok, so after creating the sql account for the bulkloader, the policy required that I change the password. Didn't catch that till I tried logging in with the account in management studio.
I am curious, though, what I would have to do differently for integrated security to work from the production server.