0

Please tell what is wrong with my connection string. I only copy the connection string from azure right now it is showing an error "Format of the initialization string does not conform to specification starting at index". When I tried to replace the double quote with single quote it says the it is missing the providerName attribute but the provider name is already included. My connection string, also I am using Entity Thank you. I know this has been asked before but I couldn't see what is wrong. What am I missing?

 <add name="sample" 
     connectionString="metadata=res://*/Models.ClearanceModel.csdl|res://*/Models.ClearanceModel.ssdl|res://*/Models.ClearanceModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;server=tcp:uppdevsecond.database.windows.net,1433;
     initial catalog=sample;Persist Security=False;UserID=sample;Password=sample;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.EntityClient" />
  • Try replacing this `Timeout=30;" providerName` with this `Timeout=30;"" providerName`. See various examples on this page https://stackoverflow.com/questions/5781059/connection-strings-for-entity-framework you are missing a closing `&quot` – Nick.Mc May 15 '21 at 07:02
  • 1
    Thank you it's working now. I tried putting the &quot earlier before I posted the question but it gave an error that "Persist security" is not a supported keyword so I assumed it must be wrong because it is provided by azure. But I look at the link you posted and in there I noticed that the connection string is different. I may have deleted some keywords due to constant editing. Thank you. – Ian Josh Lim May 15 '21 at 07:17

2 Answers2

0

&quot is an escaped version of ". You can't have an opening &quot without a closing &quot

I've added line feeds for clarity but the bit you're missing is after Connection Timeout=30

 <add name="sample" 
     connectionString="metadata=res://*/Models.ClearanceModel.csdl|res://*/Models.ClearanceModel.ssdl|res://*/Models.ClearanceModel.msl;provider=System.Data.SqlClient;
provider connection string=&quot;server=tcp:uppdevsecond.database.windows.net,1433;
initial catalog=sample;
Persist Security=False;
UserID=sample;
Password=sample;
MultipleActiveResultSets=False;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30&quot;" providerName="System.Data.EntityClient" />

I found a bunch of examples here Connection Strings for Entity Framework

Nick.Mc
  • 18,304
  • 6
  • 61
  • 91
0

Always check the format of your connection string. I will post the correct connection string format that I used, hopefully this could help other's in the future who will encounter the same problem.

  <add name="sampleName" 
         connectionString="metadata=res://*/Models.YourModel.csdl|res://*/Models.YourModel.ssdl|res://*/Models.YourModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;server=YOUR SERVER;
         initial catalog=YOUR DATABASE;Persist Security Info=False;User ID=YOUR USERNAME;Password=YOUR PASSWORD;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30&quot;" providerName="System.Data.EntityClient" />

Add do not forget those "&quot"