CreateDatabase / DatabaseExists Question [modified]
-
Hi All, I'm just using these for the first time and I'm seeing some odd behaviour with the DatabaseExists() method. Basically, its always returning false even when the database exists! I'm basically testing a class that ensures the required database for an application exists and is accessible before going on to use it. The class is:
internal static class DatabaseCreator { public static bool DirectoryExisted { get; private set; } public static bool DirectoryCreated { get; private set; } public static bool DatabaseExists { get; private set; } public static bool DatabaseCreated { get; private set; } public static string AppPath { get; private set; } static SSdb \_context; static DatabaseCreator() { string temp = System.Reflection.Assembly.GetExecutingAssembly().Location; AppPath = temp.Replace("DataLayer.dll", ""); } public static void CheckDatabase() { \_context = new SSdb(Properties.Settings.Default.SSDatabase); if (!Directory.Exists(AppPath + "\\\\Database")) { DirectoryExisted = false; Directory.CreateDirectory(AppPath + "\\\\Database"); DirectoryCreated = true; DatabaseExists = false; \_context.CreateDatabase(); } else { if (!\_context.DatabaseExists()) { \_context.CreateDatabase(); } } } }
All is working fine if the database isn't there, this class happily pops off and creates the correct shape database in the correct location. I've tested the database by connecting to it via Visual Studio with the expected connection string and password and so on, all is as it should be. The problem happen when I run this class when the database is already in existence, it tries to create it again and says that the file already exists! Am I doing something obviously wrong here? Anyone else seen this sort of thing? Could it be related to the fact that the connection string I'm using is:
"Data Source=|DataDirectory|\\DataBase\\SSdb.sdf;Password=*********;Persist Security Info=True"
I don't see how though because if this was an issue it would fail on the CreateDatabase() method as well ... Thanks in advance ...
Jammer Going where everyone here has gone befor
-
Hi All, I'm just using these for the first time and I'm seeing some odd behaviour with the DatabaseExists() method. Basically, its always returning false even when the database exists! I'm basically testing a class that ensures the required database for an application exists and is accessible before going on to use it. The class is:
internal static class DatabaseCreator { public static bool DirectoryExisted { get; private set; } public static bool DirectoryCreated { get; private set; } public static bool DatabaseExists { get; private set; } public static bool DatabaseCreated { get; private set; } public static string AppPath { get; private set; } static SSdb \_context; static DatabaseCreator() { string temp = System.Reflection.Assembly.GetExecutingAssembly().Location; AppPath = temp.Replace("DataLayer.dll", ""); } public static void CheckDatabase() { \_context = new SSdb(Properties.Settings.Default.SSDatabase); if (!Directory.Exists(AppPath + "\\\\Database")) { DirectoryExisted = false; Directory.CreateDirectory(AppPath + "\\\\Database"); DirectoryCreated = true; DatabaseExists = false; \_context.CreateDatabase(); } else { if (!\_context.DatabaseExists()) { \_context.CreateDatabase(); } } } }
All is working fine if the database isn't there, this class happily pops off and creates the correct shape database in the correct location. I've tested the database by connecting to it via Visual Studio with the expected connection string and password and so on, all is as it should be. The problem happen when I run this class when the database is already in existence, it tries to create it again and says that the file already exists! Am I doing something obviously wrong here? Anyone else seen this sort of thing? Could it be related to the fact that the connection string I'm using is:
"Data Source=|DataDirectory|\\DataBase\\SSdb.sdf;Password=*********;Persist Security Info=True"
I don't see how though because if this was an issue it would fail on the CreateDatabase() method as well ... Thanks in advance ...
Jammer Going where everyone here has gone befor
You're in the wrong forum. This should be asked in the ADO.NET or C# forums.
Life, family, faith: Give me a visit. From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?" Judah Himango
-
You're in the wrong forum. This should be asked in the ADO.NET or C# forums.
Life, family, faith: Give me a visit. From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?" Judah Himango