Trouble publishing ASP.NET project with Code First database to Azure - Permission - c#

I cannot migrate my Code First database to Azure - Error hints at permission, but I can't figure out what's missing?
I have created an empty SQL-database in Azure
(I can publish the web site without the EF migration)
Connection string in appsettings.json (+Development+Production) - Startup: ConfigureServices - DbContext gets the right connectionstring
serviceDependencies points to the right connectionstring - Local to LocalSecretsFile and Web Deploy to AzureAppSettings
I have commented out the LocalDB connection though (and changed reference in ConfigureServices)
I haven't deleted old migrations
Azure: App Service - Configuration - Application Settings -> Connection string is set
Azure: SQL Server - Access control (Classic administrator): Service administrator (me) has full access
Azure: SQL Server - Firewalls and virtual networks: Client IP + App Inbound + 6 * App Outbound applied - 'Deny public network access' is not checked - Yes to 'Allow Azure services and resources ...'
When publishing:
(Also tried running Visual Studio as administrator)
I can Validate connection
'File Publish Options': I choose 'Remove additional files at Destination'
'Databases': 'NameofConnStr': Use this connection string at runtime
'Entity Framework Migrations': Apply this migration on publish
'Site Extensions Options': Tried both with and without this
(I do not use the Key Vault)
Result:
Publish Executing command: dotnet ef migrations script --no-build --idempotent --configuration Release --output "..."
Generating Entity Framework SQL scripts completed successfully
Adding sitemanifest (sitemanifest)
Adding Child sitemanifest
Error: Web deployment task failed. (Make sure the database connection string for the server is correct and that you have appropriate permission to access the database. (Web Deploy Provider is "dbFullSql").
Error details:Could not complete an operation with the specified provider ("dbFullSql") when connecting using the Web Management Service. This can occur if the server administrator has not authorized the user for this operation
Learn more for "ERROR_USER_NOT_AUTHORIZED_FOR_DBFULLSQL": Web Deploy error codes - Diagnosis: A non-administrative user attempted to perform an operation with a Web Deploy provider for which the user is not currently authorized
(Build succeeded, Publish failed)
What's missing?
Should I add a new migration (and delete the old ones)?
Is there some problem with commenting out the connection to LocalDb?
Is there some setting in Azure I missed?

Well I finally succeeded in migrating my database.
I upgraded Visual Studio 2019 from 16.11.13 to 16.11.14. That's probably not the reason why it worked, but I just note it because I'm not sure what made the difference.
If someone has the same problem I'll try to summarize what worked although I think I have tried the combinations below before:
Ran Visual Studio as admin
I deleted the previous migrations (made in LocalDB) and added a new
The connectionstring only had Data Source/Initial Catalog/User Id/Password - i.e. not MultipleActiveResultSets/Encrypt/TrustServerCertificate/Connection Timeout
I ignored KeyVault (and LocalDB) service dependencies
New Publishing Profile
Published the Web app first (without migration)
Chose Apply migration and published again
All seems straight forward so it's a bit of a mystery ?!

Related

Unable to run web api (gateway) project - This localhost page can’t be found. No webpage was found for the web address:

I am trying to setup and run this git project - https://github.com/johnph/simple-transaction#WebApi-Endpoints
I have successfully clean up and re-build the whole solution. I have successfully configure to perform EF Core Code-First migration and database was successfully created with 2 tables in it:
AccountTransaction
AccountSummary
I could run Transaction.WebApi which opens up http://localhost:60243/swagger/index.html. But, I could not run the other 2 web api projects: Gateway.WebApi or Identity.WebApi. The error occured is This localhost page can’t be found. No webpage was found for the web address:
I could start SimpleBanking.ConsoleApp project. Test data is \src\Services\Identity\Services\UserService.cs. But it returns Object reference not set to an instance of an object. App interrupted. App closed.
I was able to run this project successfully.
Make sure you run 3 servers Gateway.WebApi, Identity and Transaction.
Only then you can run Console app.
In the Console even if you put the incorrect username or password the system still telling you it Login successfully, which misleading. Then when you choose one of the options you get:
Object reference not set to an instance of an object.
App interrupted.
App closed.
Make sure to monitor the log for errors

Error using ASP.NET Core in Ubuntu with Plesk

I installed NET Core SDK on Ubuntu 18.04 following the official guide:
https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install
I created a C# Hello World project with command dotnet new razor and published with dotnet publish.
I configured a new domain in Plesk with a sub-domain.
I configured (using the official reference: https://learn.microsoft.com/it-it/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-2.2) in Plesk, under Apache & nginx Settings, with the following example:
Additional directives for HTTP/HTTPS:
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName sub.mydomain.com
ServerAlias *.mydomain.com
ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
I moved the published project under subdomain folder and started it with command dotnet myproject.dll
I received the following output:
Hosting environment: Production
Content root path: /var/www/vhosts/mydomain.com/sub.mydomain.com
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
Opening sub.mydomain.com in browser I receive the following error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at logx.edotto.com Port 80
In subdomain log I can see only this:
Can someone give me a hint to look somewhere to resolve this error?
There's something I can check to receive further details about the error?
Fist you need temporary to disable the nginx since using plesk as platform panel, flow of data exchange is:
end-user-request-start -> nginx -> apache [ script/code executed ] -> reverse/proxy request back to nginx -> final result to end-user.
Plesk Location from were you can temporary disable the nginx:
Server Managment -> Tools&Settings -> Services -> Reverse Proxy Server (nginx ) - ( click on stop icon and wait for a while, once the service is stopped green check mark will disappear and grey circle will be present )
Now all request will be served by only apache2 , and then following official Microsoft Apache2 directives can be applied and sub-domain will be able to serve the requests that are ending into Kestrel server ( which will have proxy and reverse proxy directives to be able to communicate with apache 2 )
Also very important ! the same apache directives that you apply under sub-domain, it's mandatory and accordingly to be applied also under apache directives main domain.
Once you are done with it, and testing is completed then , you can re-enable the nginx reverse proxy service , and under appropriate domain, sub-domain, under nginx settings , check-box Proxy mode - needs to be selected, in order the nginx to use the apache and within the directives
example for apache directives if sub-domain has ternary or quarter name :
main domain: main-domain.com
**- ServerName: subdomain-name2.sub-domain-name1.main-domain.com
**- ServerAlias: *.main-domain.com
sub-domain: subdomain-2.sub-domain-name1.main-domain.com
**- ServerName: subdomain-name2.sub-domain-name1.main-domain.com
**- ServerAlias: *.subdomain-1.main-domain.com
Also please include in both, sud-main and main-domain, apache2 directives on top as first line:
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
And you can change if you like the errors and access activities in the logs to appear in the same log as apache2 is using ( error.log and access.log ) - this minor change will enable using plesk webplatform and mobile app to appear the logs and activities to be accessible within.
That changes can be done with small change in the following lines:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Also if you deside to use the dotnet core application as an service as it's described into Microsoft link: using systemctl , be carrefull that installation of systemctl will substitute the upstream ( service module/controler which plesk is using , at least in my Ubuntu 14.04 messed-up, potentially the kernel version and systemctl since is older, and plesk is not re-writing in the same place the symbolic links, )
- Only if your server is Ubuntu 14.04 and Plesk and you have installed the systemctl ( which was not installed by default ) execute the following to recover the symbolic link issues, ( in this use-case scenario, systemctl monitors/runs the dotnet core 2.1 application )
sed -i.orig s/systemctl/systemctl_pp/g /opt/psa/admin/sbin/pleskrc
And after this command is executed, into Plesk WebPro WebPanel, under-Home, within notification error message there are ( two links marked with here ) click - here the link that refers to: recreate all-apache2 configuration files, wait for it, and once done the Plesk Server will continue with OK state, and you'll have Plesk up and running with both nginx - as reverse-proxy towards apache and active and running dotnet core are service using systemctl.

Dotnet Restore Failed on Build Server

I have a little dotnet core application and want to build it on jenkins.
In order to make it happen, ive installed dotnet core on the build slave.
Locally i can restore with the same command successfuly (even on my mac)
dotnet restore --configfile .nuget/NuGet.Config
On the build server the restore fails for one package.
Started by user jenkins
Building remotely on 2c3bff31e594 in workspace /root/workspace/Test
Cloning the remote Git repository
...
+ dotnet restore --configfile .nuget/NuGet.Config
Welcome to .NET Core!
---------------------
...
log : Installing System.Runtime 4.1.0-rc2-24027.
log : Installing System.Diagnostics.Tools 4.0.1-rc2-24027.
log : Installing System.Reflection.Extensions 4.0.1-rc2-24027.
...
log : Restoring packages for /root/workspace/Test/test/Test.DataAccess.Tests/project.json...
log : Failed to download package from 'https://api.nuget.org/v3-flatcontainer/remotion.linq/2.1.1/remotion.linq.2.1.1.nupkg'.
log : Response status code does not indicate success: 404 (Not Found).
The strange thing here is, that if i hit the url
"https://api.nuget.org/v3-flatcontainer/remotion.linq/2.1.1/remotion.linq.2.1.1.nupkg" link from the log, the package is their.
probably a firewall or any other local setting
probably firewall. id install fiddler on the computer and look what is the exact request
add fiddler as nuget porxy like this:
https://docs.nuget.org/consume/nuget-config-settings#proxy-settings
Proxy settings
section: config
keys: http_proxy, http_proxy.user, http_proxy.password and no_proxy.
Allows you to set the proxy settings to be used while connecting to your NuGet feed. More details here.
This key can be added using NuGet.exe Config -Set command.
It can also be set via environment variables http_proxy and no_proxy. http_proxy should be specified in the format http://[username]:[password]#proxy.com whereas no_proxy should be a comma-separated list of domains to bypass the proxy server.
Note
The "http_proxy.password" key value is encrypted before storing in the nuget.config file. Hence it can not be added manually by directly updating the config file.

ASP.NET Access denied for user (using password: NO) after deploy with msbuild/msdeploy

I'm setting up ci-deployment using jenkins for multiplice ASP.NET MVC 5 EF CF application with MySQL-Database on a Windows Server 2012 R2 node. The app gets compiled first using msbuild and then published on IIS with msdeploy. ConnectionStrings will be replaced using the -setParamFile parameter, which works.
The problem: After calling the app on the target server, I get the following MySQL error:
MySql.Data.MySqlClient.MySqlException: Access denied for user 'myUser'#'myIp' (using password: NO).
The MySQL-Doc say that this means the clinent had tried to connect without password.
This is really confusing me because my ConnectionString certainly contains a password! In the Web.config from the folder of the IIS-App it looks like this:
<add name="MyContext" connectionString="Server=SERVERIP;Database=MYDBNAME;Uid=DATABASEUSER;Pwd=PWD;Convert Zero Datetime=True;" providerName="MySql.Data.MySqlClient" />
Which is valid, because the app is running fine on local debugging and a Windows Server 2012 R2 based testsystem, where I deployed the app using Web-Publishing function of Visual Studio.
I have the suspicion that my Web.config gets overwritten, but can't find out where and why. I took a look in the local Machine.config file of the target-server, but in contrast to another thread with nearly the same problem this isn't containing my ConnectionString (And I even can't imagine why this should gonna happen).

Error while starting Storage Emulator on windows azure

I'm getting the error below while starting the storage emulator. By mistake I deleted the mdf and log files in users/admin folder. It's holding reference someplace and not allowing me to create the DB again. Please help me.
Added reservation for 127.0.0.1:10000/ in user account RaviBorra-PC\Ravi Borra.
Added reservation for 127.0.0.1:10001/ in user account RaviBorra-PC\Ravi Borra.
Added reservation for 127.0.0.1:10002/ in user account RaviBorra-PC\Ravi Borra.
Found SQL Instance (localdb)\v11.0.
Creating database DevelopmentStorageDb201206 on SQL instance '(localdb)\v11.0'.
Cannot create database 'DevelopmentStorageDb201206' : Database 'DevelopmentStorageDb201206' already exists. Choose a different database name..
One or more initialization actions have failed. Resolve these errors before attempting to run the storage emulator again. Please refer to http://go.microsoft.com/fwlink/?LinkID=248088 for more details.
Thank you,
Ravi Krishna B.
Do these steps:
Open cmd.exe (Command Prompt)
Write this:
SqlLocalDb stop "v11.0"
SqlLocalDb delete "v11.0"
and press Enter
Note that "v11.0" is MyInstance.
For more details, visit this link.
This problem may occur if you delete the data file C:\Users\<Username>\DevelopmentStorageDb201206.mdf but do not delete the corresponding database on the LocalDB server instance. One possible solution is:
Connect to the (localdb)\v11.0 instance from SQL Server Management Studio.
Delete the DevelopmentStorageDb201206 database. There will be the error message that the database deletion ended with an error. Ignore this message and refresh the database list manually.
Now you can start the Azure Storage Emulator.
This is not a problem related with Azure components rather LocalDB instance is reporting back to Azure request that DB still exist. Check LocalDB instances in your machine using "sqllocaldb i" first and the delete the instance using "sqllocaldb d 'instance_name'". I could not test it in my machine but this may unblock you if localdb instance is blocking you.
In Windows Azure SDK 1.7, Windows Azure Storage Emulator uses LocalDB instance specific configuration at following location:
%LocalAppData%\DevelopmentStorage\DevelopmentStorage.201206.config
And based on that you will see that v11.0 instance is Windows Azure Storage Emulator specific so verify if that is running and deleting it will let DSInit to create the DB again in LocalDB.
If you have Sql Express installed on your local box then (localdb)\v11.0 is most likely not your local Sql instance. It is more likely {MyComputerName}\SQLEXPRESS.
Going to:
C:\Users\<yourloginname>\AppData\Local\DevelopmentStorage\DevelopmentStorage.201206.config
And changing:
<SQLInstance>(localdb)\v11.0</SQLInstance>
To:
<SQLInstance>{MyComputerName}\SQLEXPRESS</SQLInstance>
solved this error for me.
I hope this helps..
If you already tried and failed perform:
SQLLocalDB stop v11.0
SQLLocalDB delete v11.0
Delete all the files in C:\Users\<accontname>\WAStorageEmulatorDb* (usually one mdf and one ldf)
Create a new account (I called it Azure, with administrative rights)
Run again the installation
Installation completed!
For me this works... I had tried to format the PC before use this way. I supposte my problem is related to my username that contains "invalid" characters like Name 'NickName' Surname while the "Azure" account seems to be OK for him.
I figure it out 'cause somewhere in the log I have a property destination path set to "C:\Users\Name$_" that is far away for the path of my user account folder.
After that you can go on CMD.exe and prompt:
control userpasswords2
From the control you can delete the Azure login without delete the file folders!
Hope it helps!
I simply deleted all the mdf's and ldf's in C:\Users\accountname\ that started with DevelopmentStorage... or WAStorageEmulator.
Re-ran the install and it worked.
This can also be caused by the folder not existing for localDB. It looks like Visual Studio / Azure will not automatically create containing folders. I just copied the path from the error code into explorer and created the directory up to the .MDF file.
In visual studio go to Tools -> Options -> Database Tools-> Data connections and change a localdb instance name from v11.0 to some other name.
I did have SQL Express installed, as Brian Ogden suggested in his answer, but I wanted to try & point Azure Storage Emulator to my SQL Express instance without modifying configuration files.
I did this by running the initialization process for Storage Emulator & passing my server\instance details for SQL Express using the available switches. Below example of the command I executed (from an elevated command prompt):
AzureStorageEmulator.exe init -server MY-PC-NAME -instance MYSQLINST
This created the database successfully (in my SQL Express instance) & got my Storage Emulator working.
I am using a named instance, but I'm thinking this same approach can be used for default instances by omitting the -instance switch.

Categories

Resources