Adding .edmx connectionString to Azure "Application Settings" - azure

So I am trying to add my connection string to Azure for an Entity Framework Database First edmx file and it's not going so well.
My conn string in Web.Config:
<add name="MyEntities" connectionString="metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MyDatabaseName.database.windows.net,1433;initial catalog=XXXXXX;persist security info=False;user id=XXXXXX;password=XXXXXXXXX;multipleactiveresultsets=False;connect timeout=30;encrypt=True;trustservercertificate=False;App=EntityFramework"" providerName="System.Data.EntityClient" />
My connection string in Azure:
"metadata=res://*/Models.MyModel.csdl|res://*/Models.MyModel.ssdl|res://*/Models.MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:MyDatabaseName.database.windows.net,1433;initial catalog=mydatabase;persist security info=False;user id=**************;password=**************;multipleactiveresultsets=False;connect timeout=30;encrypt=True;trustservercertificate=False;App=EntityFramework""
Please tell me what I'm doing wrong... I've looked at 5 posts that tell me to just cut and paste my connection string in there, but they don't mention is leading or trailing quotes are needed... Also not sure that it's going to work for an edmx... I've tried using "custom" also.
Thanks so much for any guidance!!

Assuming you are trying to configure a connection string directly in the azure portal for the webapp, you have to make sure of 3 things
1) Replace " with single quote (‘) from the original connection
string that is set in web.config so mine becomes
metadata=res://*/Clash.csdl|res://*/Clash.ssdl|res://*/Clash.msl;provider=System.Data.SqlClient;provider connection string='data source=server.database.windows.net,1433;initial catalog=db;user id=websiteadmin#server;password=************;MultipleActiveResultSets=True;App=EntityFramework'
2) Make sure that the connection string type is CUSTOM
3) Leave a dummy connection string configuration in the web.config like this
<connectionStrings>  <add name="nextgenplusEntities" connectionString="dummy"providerName="System.Data.EntityClient"/>
If I remove the dummy connection string then things fail for me….
Server Error in '/' Application.
The connection string 'nextgenplusEntities' in the application's configuration file does not contain the required providerName attribute."
Hope this helps.

Related

Api error System.ArgumentException: Format of the initialization string does not conform to specification starting at index 258

I'm currently trying to work through connecting to a cloud-based database with an Api I've found a lot of similar questions but all the fixes I have found on stack haven't worked for my solution any help would be appreciated
[Error that the Api is showing - program.cs ConnectionString ]
ConnectionString in appsettings:
"ConnectionStrings": {
"MyContext":
"Server=tcp:removed.database.windows.net,1433;Initial Catalog=kawamaraedb;Persist Security Info=False;User ID=Removed;Password='Removed';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},
ID and Password are correct
My fix
I figured it out i had to manually type in the connection string from azure and take out alot of the added code string
FROM THIS:
Server=tcp:sql.database.windows.net,1433;Initial Catalog=YOUR DB;Persist Security Info=False;User ID={USER};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
TO THIS
"Data Source=tcp:sql.database.windows.net,1433;Initial Catalog=YOUR DB;User Id={USER};Password={YOUR PASSWORD}"
It's not related to Visual Studio 2022. It seems that the connection string is not correct. For instance, InitialCatalog is not a valid key and should be Initial Catalog. You may discover more at Connection String Property

Connection to Entity Framework works locally, Was working in Azure but now I get "Invalid object name..."

I have looked through various posts related to this problem, but none provide an answer. I created a .Net 5.0 app that accesses an Azure SQL DB using EF 6.4.4 which works with .Net standard libraries. I modified the EF by adding a function that creates the connection string from appsettings.json since .Net 5 apps don't use a web.config file. This also works well in Azure with the configuration settings in an app service.
The connection string looks like this:
metadata=res://*/EF.myDB.csdl|res://*/EF.myDB.ssdl|res://*/EF.myDB.msl;provider=System.Data.SqlClient;provider connection string='Data Source=tcp:mydb.database.windows.net,1433;Initial Catalog=myDB;Integrated Security=False;Persist Security Info=False;User ID=myuserid#mydb;Password="password";MultipleActiveResultSets=True;Connect Timeout=120;Encrypt=True;TrustServerCertificate=True'
I also have a deployment pipeline that will deploy the code after a check-in instead of using the Visual Studio publish feature, but the pipeline deployed code has the same problem.
When I first created the app and published it to the app service, it worked. Recently I updated the app with no changes to the EF connection. Now I get the "Invalid Object name when I reference any table in the model. If I run the same code locally and connect to the Azure SQL DB, the DB is accessed as expected. This problem only occurs when running in the Azure app service. Note that there are no connection strings configured for the app service since the EF string is built from the config settings. I saw this post, but I don't think it applies:
Local works. Azure give error: Invalid object name 'dbo.AspNetUsers'. Why?
even though the problem is the same. I have also read various posts about the format of the EF connection string. Since my model is database first, (and the connection used to work), I'm confident the string has the correct format. I don't think the problem is in the code since it works when running locally with a connection to the Azure SQL DB. It must have something to do with the Azure app service configuration, but I'm not sure what to look for at this point. Unfortunately I don't have a copy of the code and publish files that did work to compare to, but it the pipeline build doesn't work either and that it how the code would normally be deployed. Thanks for any insight you might have!
UPDATE
metadata=res://*/EF.myDB.csdl|res://*/EF.myDB.ssdl|res://*/EF.myDB.msl;provider=System.Data.SqlClient;provider connection string='Data Source=tcp:yourdbsqlserver.database.windows.net,1433;Initial Catalog=yourdb;Persist Security Info=False;User ID=userid;Password=your_password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30'
When the troubleshooting problem is not on the string, our easiest way is to use vs2019 to re-use the generated string.
Your connection string should be like below.
<connectionStrings>
<add name="SchoolDBEntities" connectionString="metadata=res://*/SchoolDB.csdl|res://*/SchoolDB.ssdl|res://*/SchoolDB.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=SchoolDB;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
For more details, you can refer my answer in the post and the tutorial.
1. Timeout period elasped prior to obtaining a connection from the pool - Entity Framework
2. Entity Framework Tutorial
The problem was one of my config settings in Azure. The catalog parameter was missing. A simple fix, but the error message was misleading, so I thought I would note that here in case anyone else gets the same "Invalid object name" message when referencing an Azure SQL DB with EF. It would have been more helpful if the message was "catalog name invalid" or "unable to connect to database".
For those who are curious about building an EF connection string, here is example code:
public string BuildEFConnectionString(SqlConnectionStringModel sqlModel, EntityConnectionStringModel entityModel)
{
SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
{
DataSource = sqlModel.DataSource,
InitialCatalog = sqlModel.InitialCatalog,
PersistSecurityInfo = sqlModel.PersistSecurityInfo,
UserID = sqlModel.UserID, // Blank if using Windows authentication
Password = sqlModel.Password, // Blank if using Windows authentication
MultipleActiveResultSets = sqlModel.MultipleActiveResultSets,
Encrypt = sqlModel.Encrypt,
TrustServerCertificate = sqlModel.TrustServerCertificate,
IntegratedSecurity = sqlModel.IntegratedSecurity,
ConnectTimeout = sqlModel.ConnectTimeout
};
//Build an Entity Framework connection string
EntityConnectionStringBuilder entityString = new EntityConnectionStringBuilder()
{
Provider = entityModel.Provider, // "System.Data.SqlClient",
Metadata = entityModel.Metadata,
ProviderConnectionString = sqlString.ToString()
};
return entityString.ConnectionString;
}
Given what I have learned, the properties should be validated before the string is returned. If the string is created this way, all of the connection string properties can be added to the config settings in the app service. I used the options pattern to get them at runtime. Thanks to everyone for your suggestions.

Excel to MS Access connection: Issues with with space in connection string

I have been able to successfully connect my excel to MS access, and using the connection, I am able to push and pull data to and from excel to Access DB. However, I noticed, if my connection string has space in between like mentioned below, I am unable to establish the connection. Is there any way around it?
Connection string with space
Set oADODBCon = New ADODB.Connection
oADODBCon.Open Microsoft.ACE.OLEDB.12.0;Data Source=\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb;Persist Security Info=False;
I have tried using single quotes in my connection string as below but it still didn't work
Set oADODBCon = New ADODB.Connection
oADODBCon.Open Microsoft.ACE.OLEDB.12.0;Data Source='\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb';Persist Security Info=False;
Any help would be much appreciated!
oADODBCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\XYZ-123\0123\ABC 2020 Test Operations\MyDb.accdb;Persist Security Info=False;"

Excel2016: Cannot query PostgresSQL database: Server certificate not accepted

I want to import some data to Excel2016 from a postgresSQL table. I have tried it by clicking "new query" and selecting From Database -> From PostgresSQL Database:
But then I receive the following error:
Details: "TlsClientStream.ClientAlertException: CertificateUnknown: Server certificate was not accepted. Chain status: A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.
. The specified hostname was not present in the certificate.
at TlsClientStream.TlsClientStream.ParseCertificateMessage(Byte[] buf, Int32& pos)
at TlsClientStream.TlsClientStream.TraverseHandshakeMessages()
at TlsClientStream.TlsClientStream.GetInitialHandshakeMessages(Boolean allowApplicationData)
at TlsClientStream.TlsClientStream.PerformInitialHandshake(String hostName, X509CertificateCollection clientCertificates, RemoteCertificateValidationCallback remoteCertificateValidationCallback, Boolean checkCertificateRevocation)"
Any suggestions on how to solve this? Thank you so much in advance!
This error is indicative of a connection being made to the PostgreSQL db where the server's certificate cannot be validated by the client making a connection. This error only happens when the "Trust Server Certificate" is set to FALSE in the library Excel uses to connect to PostgreSQL (npgsql).
There are several ways that may work to address this, in the order I'd suggest trying them:
If there's an option hidden in Excel (perhaps under advanced options or similar) to set the 'Trust Server Certificate' parameter to True, then your connection will start working. If it allows you to specify an entire connection string, then this can be done in the connection string as well.
The database should have a public key in an SSL cert listed in the postgresql.conf file for the db. If you (or your db administrator) can get that public key and add it to your machine (instructions will vary depending on your operating system).
I have finally found a workaround for my problem.
What you can do is to:
Install the current postgresql driver from here
Follow the instruction from this video
With this, you can connect to your postgreSQL database by ODBC.

Breeze DTO Service -- Metadata query failed for: breeze/DTO/Metadata; An error has occurred -- Error

We are using Breeze in our SPA (Durandal), till now we were using EF5 to return the metadata Breeze requires, but now we want to use DTO in certain scenarios, so we have implemented it following http://www.breezejs.com/documentation/ef-design-tool, it works well in development environment but when we deploy it on IIS it returns "Metadata query failed for: breeze/DTO/Metadata; An error has occurred."
I have checked the paths to the service is correct.
Please help....
I was able to resolve the issue the root cause was that an dummy connection string is required for DTO to work especially in the case if Webdeploy is being used to publish the code. I referred the Breeze Sample "DocCode" web config --
<!-- TODO: is this needed?
phony FoosMetadataContext connection enables FoosMetadataProvider to succeed; there is no nonsense.sdf-->
<add name="FoosMetadataContext" connectionString="Data Source=|DataDirectory|nonsense.sdf" providerName="System.Data.SqlServerCe.4.0" />

Resources