Click here to Skip to main content
15,891,372 members
Home / Discussions / C#
   

C#

 
QuestionHow can we enable <b>CTRL+A</b> on textBox in C# form ? Pin
Mohammad Dayyan25-Jun-08 11:36
Mohammad Dayyan25-Jun-08 11:36 
AnswerRe: How can we enable CTRL+A on textBox in C# form ? Pin
DaveyM6925-Jun-08 13:18
professionalDaveyM6925-Jun-08 13:18 
GeneralRe: How can we enable CTRL+A on textBox in C# form ? Pin
Mohammad Dayyan25-Jun-08 21:41
Mohammad Dayyan25-Jun-08 21:41 
GeneralRe: How can we enable CTRL+A on textBox in C# form ? Pin
DaveyM6925-Jun-08 22:18
professionalDaveyM6925-Jun-08 22:18 
QuestionMouse and Keyboard Scripting Pin
Michael Fritzius25-Jun-08 10:56
professionalMichael Fritzius25-Jun-08 10:56 
AnswerRe: Mouse and Keyboard Scripting Pin
Christian Graus25-Jun-08 18:29
protectorChristian Graus25-Jun-08 18:29 
GeneralRe: Mouse and Keyboard Scripting Pin
Michael Fritzius26-Jun-08 3:27
professionalMichael Fritzius26-Jun-08 3:27 
QuestionCreateDatabase() / DatabaseExists() Question Pin
Jammer25-Jun-08 9:39
Jammer25-Jun-08 9:39 
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 in C# using my LINQ datacontext that ensures the required database for my 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 application can also carry on and use this database. The problem happens 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? I know the class needs some work before it is rock solid but this basic functionality should be ok as is.

What I've noticed is that this problem only occurs when the connection sting in use is as follows:

"Data Source=|DataDirectory|\\DataBase\\SSdb.sdf;Password=*********;Persist Security Info=True"


If I use a connection string replacing |DataDirectory| with the full path the DatabaseExists() method works as expected.

I'm not getting why CreateDatabase() can use the |DataDirectory| path ok, but DatabaseExists() cannot. Is this a bug in the framework or am I missing something regarding the use of these methods? I don't know if this makes any difference but I'm using SQL Compact 3.5.

Thanks in advance ...

Jammer

Going where everyone here has gone before! Smile | :)
My Blog

AnswerRe: CreateDatabase() / DatabaseExists() Question Pin
Judah Gabriel Himango25-Jun-08 18:07
sponsorJudah Gabriel Himango25-Jun-08 18:07 
GeneralRe: CreateDatabase() / DatabaseExists() Question Pin
Jammer26-Jun-08 2:57
Jammer26-Jun-08 2:57 
GeneralRe: CreateDatabase() / DatabaseExists() Question Pin
Jammer26-Jun-08 7:20
Jammer26-Jun-08 7:20 
QuestionHow can I convert this string to the image? Pin
Mohammad Dayyan25-Jun-08 9:33
Mohammad Dayyan25-Jun-08 9:33 
AnswerRe: How can I convert this string to the image? Pin
Guffa25-Jun-08 9:44
Guffa25-Jun-08 9:44 
AnswerRe: How can I convert this string to the image? Pin
hammerstein0525-Jun-08 9:45
hammerstein0525-Jun-08 9:45 
GeneralRe: How can I convert this string to the image? Pin
Mohammad Dayyan25-Jun-08 9:56
Mohammad Dayyan25-Jun-08 9:56 
GeneralRe: How can I convert this string to the image? Pin
hammerstein0525-Jun-08 10:13
hammerstein0525-Jun-08 10:13 
GeneralRe: How can I convert this string to the image? Pin
Mohammad Dayyan25-Jun-08 10:21
Mohammad Dayyan25-Jun-08 10:21 
GeneralRe: How can I convert this string to the image? Pin
Guffa25-Jun-08 10:29
Guffa25-Jun-08 10:29 
GeneralRe: How can I convert this string to the image? Pin
hammerstein0525-Jun-08 10:34
hammerstein0525-Jun-08 10:34 
GeneralRe: How can I convert this string to the image? Pin
Mbah Dhaim25-Jun-08 22:39
Mbah Dhaim25-Jun-08 22:39 
GeneralRe: How can I convert this string to the image? Pin
Mohammad Dayyan25-Jun-08 10:16
Mohammad Dayyan25-Jun-08 10:16 
GeneralRe: How can I convert this string to the image? Pin
hammerstein0525-Jun-08 10:22
hammerstein0525-Jun-08 10:22 
GeneralRe: How can I convert this string to the image? Pin
Mohammad Dayyan25-Jun-08 10:36
Mohammad Dayyan25-Jun-08 10:36 
QuestionUse Ctrl+F1 to cycle between MDI child windows Pin
AndrusM25-Jun-08 7:46
AndrusM25-Jun-08 7:46 
QuestionUsing Ctrl+E menu shortcut from readonly control Pin
AndrusM25-Jun-08 7:43
AndrusM25-Jun-08 7:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.