Monday, March 12, 2012

Request for SqlCeEngine.Exists(), .Delete() methods

Given a connection string, I can create a database using a SqlCeEngine object and call engine.CreateDatabase().

However, there doesn't seem to be a way to determine whether a database exists, given a connection string. I would need to interpret the connection string myself and extract the file name to use File.Exists() etc.

There should be SqlCeEngine methods to test whether a database exists, test whether it's accessible, and to delete it, given a connection string.

Cheers, Oli

It is unlikely that would be added as you can easily do that with simple string manipulations and classes from System.IO – you already know how.

In compact world (where keeping size down is very important) functionality is usually added only if it’s not possible (or very hard) to do or if it’s some very common task. One example would be multiple connections support added in SQL Mobile. Your task is easy to do with existing functionality and it’s not that common – usually connection string is constructed from file name.

In any case you’re welcome to submit a request via Product feedback site: http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220

|||

Hmm...I can get you a work around if you are taking connection string as input.

This should help you!

conn = new SqlCeConnection(inputConnectionString);

if (File.Exists(conn.DataSource))

File.Delete(conn.DataSource);

The important thing to note here is that, Connection Object parses the connection string the moment you assign it (need not call Open). And DataSource property will return the Database File Path.

Thanks,

Laxmi

No comments:

Post a Comment