RSS 2.0
# Wednesday, January 12, 2011

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.  Smile

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.

image

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.

Technorati Tags: ,
Wednesday, January 12, 2011 7:42:48 PM UTC  #    Comments [2] -
Entity Framework | mvc
Friday, January 14, 2011 2:53:49 PM UTC
I was browsing the comments over on Scott Gu's website, and saw your comment. Happy birthday!
Friday, January 14, 2011 5:21:48 PM UTC
Thanx John!
Comments are closed.
Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
George Handlin
Sign In
Statistics
Total Posts: 51
This Year: 0
This Month: 0
This Week: 0
Comments: 9
All Content © 2012, George Handlin
DasBlog theme 'Business' created by Christoph De Baene (delarou)