0

We have upgraded an application to use Microsoft.Data.SqlClient from System.Data.SqlClient because we need Always Encrypted support. However, upon upgrading it is throwing an exception open attempting to create a new SqlConnection. I've tried various permutations of connection string flavor but nothing has helped.

using (var conn = new SqlConnection(@"Server=MyServer;Database=MyDb;Connect Timeout=60; uid=admin;pwd=password") //Throws XmlException - "Root element is missing"
{
    conn.Open(); 
}

Stack trace (not very helpful)

This exception was originally thrown at this call stack:
    System.Xml.XmlTextReaderImpl.Throw(System.Exception)
    System.Xml.XmlTextReaderImpl.ParseDocumentContent()
    System.Xml.XmlTextReaderImpl.Read()
    System.Xml.XmlTextReader.Read()
    System.Configuration.XmlUtil.XmlUtil(System.IO.Stream, string, bool, System.Configuration.ConfigurationSchemaErrors)
    System.Configuration.BaseConfigurationRecord.InitConfigFromFile()

Any ideas on how to fix this?

MgSam
  • 12,139
  • 19
  • 64
  • 95
  • Sounds like a bug, and you'd want to file an issue for that. – mason May 26 '20 at 20:42
  • What's the stack trace? Have you perhaps got a corrupt config file? – David Browne - Microsoft May 26 '20 at 20:44
  • @DavidBrowne-Microsoft I added the (useless) stack trace it's giving me. I initially said it was on Open but it actually seems to actually be in the constructor. I put the cnn string in there directly to rule out any config file issue. – MgSam May 26 '20 at 20:54
  • Yep. You've got a corrupted configuration file. Either YourApp.exe.config, web.config, or the Machine.Config. – David Browne - Microsoft May 26 '20 at 21:14
  • @DavidBrowne-Microsoft Why is it looking in any file when I manually pass a connection string to its constructor? System.Data.SqlClient was working perfectly prior to the upgrade. – MgSam May 26 '20 at 21:44
  • They should both need to read your app config file and the machine config file, and a quick test with procmon shows that they both do. – David Browne - Microsoft May 26 '20 at 22:27
  • 1
    @DavidBrowne-Microsoft Deleting the app.config file worked, thanks. Though this is definitely a regression from System.Data.SqlClient because we made no code changes and this started happening. That said, I failed when trying to make a simple repro project so I'm not sure how to report this on Github. – MgSam May 27 '20 at 00:20

0 Answers0