Ok, so maybe that’s not correct … do Roman numerals even have decimals. Hmmm… maybe I should have paid a bit more attention in that class. In Part I we set up our classes and data access “layer”. Thanks to ErikEJ letting me know of a provider that he – uh – provided for SQL CE, we’ll integrate that in. Since this wasn’t in the original plan, we’ll call this I.V or 1.5.
You can go get the files from here. I’m just going to include the files rather than the binary. I found an issue in the SqlCeMembershipUtils.cs file in the CreateDatabaseIfNeeded method. It has to do with how the path shows up. When checking for the file, the connection returns the following for the Database (path) property, which of course is not the path to the actual sdf file. The connection works however.
So, I’ve modified that method like so:
public static void CreateDatabaseIfRequired(string connection) { string dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory") as string; string physConnectionString = connection.Replace("|DataDirectory|", dataDirectory); string[] parts = connection.Split('|'); string physFileString = Path.Combine(dataDirectory, parts[parts.Length - 1]); string sdfPath = string.Empty; lock (_lock) { using (var testConn = new SqlCeConnection(physConnectionString)) { sdfPath = testConn.Database; } if (string.IsNullOrWhiteSpace(sdfPath)) return; if (!System.IO.File.Exists(physFileString)) { //OK, try to create the database file using (var engine = new SqlCeEngine(connection)) { engine.CreateDatabase(); } } ValidateDatabase(connection); } }
You will of course need to modify the connections in web.config for the membership provider and add using System.IO; to the top. The other option would be to skip the file check and just eat the exception if it’s because of the file already existing.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.