Migrate .NET Core app from Google App Engine to Google Cloud Run - SQL connection issues - asp.net-core

I have a .NET Core API currently running in App Engine and everything is working fine there. I am connecting to the database by following Google provided example, defining cloud sql instance in app.yaml:
beta_settings:
cloud_sql_instances: <sql connection name>
Along with env variables like DB_HOST: cloudsql and other credentials.
Note that I am using a custom runtime and provide the dockerfile myself.
While trying to deploy my app to Cloud Run, I've tried setting up the environment variables in the same way as I am providing them in my app.yaml file, as well as providing cloud sql connection name and adding it (note that I could not see the connection name I want, out of 4 existing SQL instances I could only see 2), the same one I use in my app.yaml. Deployment fails with an error:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or
instance-specific error occurred while establishing a connection to SQL Server. The server was
not found or was not accessible. Verify that the instance name is correct and that SQL Server
is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal
exception was caught)
I've tried following this post, but still nothing changed. Other attempts:
I've configured my SQL instance to have a private IP assigned and tried using it at DB_HOST field, still got the exception
Tried changing SQL connection name to other instances (appropriately changing environment variables), still got the exception
Created a VPC Connector and added it to my revision, still got the same error.
How can I fix this? What am I doing wrong?

If you are migrating an existing web application, see Migrating Your Service to Cloud Run.
Check if your app meets all the criteria for Cloud Run.
Checked this document about connecting to a Cloud SQL instance from a service running in Cloud Run. The steps to configure Cloud Run depend on the type of IP address you assigned to your Cloud SQL instance. You can also check about connection options.
You can follow this example about Google Cloud SQL with MySQL for Cloud Run.
It could be helpful to check this SO post about the correct Cloud SQL connection string syntax for dotnetcore app with Cloud Run.

Alright so I managed to make it work by following this quickstart guide, it's quite confusing really to have many different sources about Cloud Run connecting to SQL. Adding the environment variables mentioned in the guide solved the issue.

Related

SQL2008 to SQL2014 authentication issues

We recently migrated an application database to a new version from winserv2008/sql2008 to winserv2012R2/Sql2014. A service that pulls on this DB needs to be redesigned to accommodate some minor table/view definition changes.
Running the service code through tests under my personal security context works fine. However, installing and starting the service under .\LocalSystem is problematic. Looking at the service logs in event viewer I see that the service tries to connect to the sql server but gets a ERROR[28000] Login failed for user 'Domain\LocalSystemName$'.
The connection is via ODBC, SQL Server Native Client 11.0. Connection string is like:
"dsn=dsn_name;Driver={SQL Server Native Client 11.0};Database=database_name;Integrated Security=False;uid=accountname;pwd=accountpassword;Connect Timeout=15;ApplicationIntent=ReadOnly;"
Also, through the course of troubleshooting I've discovered/confirmed several things.
The sql server credentials I am using are correct, they are also being used to connect from a SQL2016 instance to the SQL14 server as a linked server.
The original service install on a utility server appears to be hitting the new database fine after the ODBC connection settings were switched.
My questions are:
Have you run into anything like this before?
Am I missing something simple in my connection string?
Are there per machine security settings in sql14 that I'm missing?

SQLExpress database file auto-creation error - after deploying to Azure

Was going about with our usual deployment of code (ASP.NET MVC solution) to Azure to a test instance as an App service. The solution works on local machine, but started throwing this exception in Azure.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
* SQLExpress database file auto-creation error: *
Unfortunately this seems to be happening even for other environments now. I haven't changed anything there except redeploying. This has nothing to do with connectionString, have triple checked it on the server itself. Basically the solution as it is works, and have been working for all this while, but since last week all new deployments are failing with this error. Even re-deploying the old code seems to fail. I am afraid to try it on any new environments.
No recent changes were made to web.config, all that was updated was some UI components. In any case, even the older code that is running on other environments are failing. Any ideas on why this could be happening?
SQLExpress only exists within Visual Studio. On something like Azure, you need a connection string that points to a real instance of a SQL Server database.

Internet Application

A default ASP.NET MVC 4 project with an account controller that uses forms authentication, but this authentication give this error on IIS 7.5 on my server.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
How can I solve this as I cant find any connections on class.
The default MVC 4 project relies on IIS Express and LocalDB, the LocalDB generated is stored in the App_Data folder.
However when changing the project to run under full IIS you are advised to switch to using SQL Express. For this you will need to create a database and set up the relevant connection string. Assuming your application has the relevant permissions and the WebSecurity.InitializeDatabaseConnection has autoCreateTables set to true the relevant tables will automatically be created.
The default database initialization is done via the InitializeSimpleMembershipAttribute we can be found in Filters/InitializeSimpleMembershipAttribute.cs this attribute is then applied to the AccountController.
You should check Windows log as suggested in exception message. Connection string is in the web.config file of your web application.

Running into an SQL Error with an MVC Application deployed on IIS

So I am new to working on web projects in general. I am working on an MVC application in Visual Studio 2008. I have generated an SQL database within VS, and I have deployed my application on IIS. However when I try to do anything in the application which will spark an SQL query, I get the following error:
"Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed."
I have hit google on this problem, and people have suggested a number of solutions but I am unsure how many of them are relevant to me doing this when I'm doing this in VS2008,. I have tried a few simple things suggested like setting the trust level to full, and setting the Load User Profile to true in IIS, but no luck yet.
What edition of SQL are you running where you deployed the application to? If it is not SQL Express, you will need to remove "User Instance=True" from the connection string.

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.