URGENT! Create Database Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Keep getting error: SQL Server CE encountered problems in creating the SQL Server CE database. [,,,Connection string,,


//-- delete database fil
if (File.Exists(@strLocalDBFile)
{
File.Delete(@strLocalDBFile)

//-- create local database
SqlCeEngine engine = new SqlCeEngine()
engine.LocalConnectionString = @strLocalConn

engine.CreateDatabase()

Error happens on CreateDatabase Command. Oddly this code works on 1 device I have but not on others
The local file name and database string are good, because they work on other device

Any ideas, I'm in a big crunch

thanks
 
gfeighny:

Just b/c it works on other devices doesn't mean it's necessarily good...for
instance Storage Card is a legit drive on my iPAQ but on my Dell it doens't
exist.

First, if you go in through Query Analyzer, can you create a Database
visually?

Second, for the path that you are referencing, do a
Debug.Assert(Path.Exists(ThePathYouaAreTryingtoUse); just to make sure the
path exists.

Also, can you post the string, otherwise the code looks good (although I'm
lazy and pass the string into the constructor to save a line of code.
However this isn't the problem).

Bill
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating the SQL
Server CE database. [,,,Connection string,,]
 
One other thing, it may already exist b/c what you are deleting isn't the
same variable name so it might be referencing something different. Say that
@strLocalConn = "DataSource = myFile.sdf; Password = whatever";

but @strLocalDbFile is "DataSource = SomeOther.sdf; Password = whatever";

You check for the existence of the second and delete it if you find it,
however, you aren't checking for the first (unless of course you are
positive they are the same file). Hence a
Debug.Assert(File.Exist("@strLocalConn")) might be helpful ...if you see a
big ugly assertion box, then that's not the problem, but if the assertion
doesn't fail, it means strLocalConn does exist and isn't letting you create
over it. In any case, having both is just going to be confusing and adding
an @ at the beginning is probably confusing too since that's the prefix for
SQL SErver parameters but these are just variables.
You can also assert (@strLocalDbFile == @strLocalConn) ; if this succeeds
then the strings match so the delete check you do will be valid, otherwise
it won't be.
Let me know if the Path in fact exists, and if the file exists, one of those
is probably the problem.
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating the SQL
Server CE database. [,,,Connection string,,]
 
It's also possible that the database file is in use by another process such
as Query Analyzer.
--
Ginny Caughey
..Net Compact Framework MVP

William Ryan eMVP said:
gfeighny:

Just b/c it works on other devices doesn't mean it's necessarily good...for
instance Storage Card is a legit drive on my iPAQ but on my Dell it doens't
exist.

First, if you go in through Query Analyzer, can you create a Database
visually?

Second, for the path that you are referencing, do a
Debug.Assert(Path.Exists(ThePathYouaAreTryingtoUse); just to make sure the
path exists.

Also, can you post the string, otherwise the code looks good (although I'm
lazy and pass the string into the constructor to save a line of code.
However this isn't the problem).

Bill
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating the
SQL
Server CE database. [,,,Connection string,,]
//-- delete database file
if (File.Exists(@strLocalDBFile))
{
File.Delete(@strLocalDBFile);
}
//-- create local database
SqlCeEngine engine = new SqlCeEngine();
engine.LocalConnectionString = @strLocalConn;

engine.CreateDatabase();

Error happens on CreateDatabase Command. Oddly this code works on 1
device
I have but not on others!
The local file name and database string are good, because they work on other devices

Any ideas, I'm in a big crunch!

thanks
 
Yep, absolutely. After I posted this, I reposted b/c I noticed that the
variables used for the localDbFile and what he was checking for /deleting
were different names and could have different values. So the check/delete
code may not find a file or it may delete it, but the createdb variable may
already exist in which case it won't be able to recreate it.

I was a little slow on my first post ;-) but good catch.
Ginny Caughey said:
It's also possible that the database file is in use by another process such
as Query Analyzer.
--
Ginny Caughey
.Net Compact Framework MVP

William Ryan eMVP said:
gfeighny:

Just b/c it works on other devices doesn't mean it's necessarily good...for
instance Storage Card is a legit drive on my iPAQ but on my Dell it doens't
exist.

First, if you go in through Query Analyzer, can you create a Database
visually?

Second, for the path that you are referencing, do a
Debug.Assert(Path.Exists(ThePathYouaAreTryingtoUse); just to make sure the
path exists.

Also, can you post the string, otherwise the code looks good (although I'm
lazy and pass the string into the constructor to save a line of code.
However this isn't the problem).

Bill
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating the
SQL
Server CE database. [,,,Connection string,,]
//-- delete database file
if (File.Exists(@strLocalDBFile))
{
File.Delete(@strLocalDBFile);
}
//-- create local database
SqlCeEngine engine = new SqlCeEngine();
engine.LocalConnectionString = @strLocalConn;

engine.CreateDatabase();

Error happens on CreateDatabase Command. Oddly this code works on 1
device
I have but not on others!
The local file name and database string are good, because they work on other devices

Any ideas, I'm in a big crunch!

thanks
 
Rya

localDBFile = "\Program Files\PocketMTrak\MTrak.sdf"
localDBConnection="Data Source=\Program Files\PocketMTrak\MTrak.sdf"

are my variables. one is a file reference, and the other is the database connection string

Attempted the Assert, and everything looks ok, even did a hard reset, and reloaded everything

I am now in the process or reseting the device that this DOES work on



----- William Ryan eMVP wrote: ----

One other thing, it may already exist b/c what you are deleting isn't th
same variable name so it might be referencing something different. Say tha
@strLocalConn = "DataSource = myFile.sdf; Password = whatever"

but @strLocalDbFile is "DataSource = SomeOther.sdf; Password = whatever"

You check for the existence of the second and delete it if you find it
however, you aren't checking for the first (unless of course you ar
positive they are the same file). Hence
Debug.Assert(File.Exist("@strLocalConn")) might be helpful ...if you see
big ugly assertion box, then that's not the problem, but if the assertio
doesn't fail, it means strLocalConn does exist and isn't letting you creat
over it. In any case, having both is just going to be confusing and addin
an @ at the beginning is probably confusing too since that's the prefix fo
SQL SErver parameters but these are just variables
You can also assert (@strLocalDbFile == @strLocalConn) ; if this succeed
then the strings match so the delete check you do will be valid, otherwis
it won't be
Let me know if the Path in fact exists, and if the file exists, one of thos
is probably the problem
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating the SQ
Server CE database. [,,,Connection string,,
 
Ok, I gotcha. Yes, that makes sense. However, this is C# so the \ needs a
@ at the beginning or a \\ where each backslash is. Could this be the
problem.
gfeighny said:
Ryan

localDBFile = "\Program Files\PocketMTrak\MTrak.sdf";
localDBConnection="Data Source=\Program Files\PocketMTrak\MTrak.sdf";

are my variables. one is a file reference, and the other is the database connection string.

Attempted the Assert, and everything looks ok, even did a hard reset, and reloaded everything.

I am now in the process or reseting the device that this DOES work on.





----- William Ryan eMVP wrote: -----

One other thing, it may already exist b/c what you are deleting isn't the
same variable name so it might be referencing something different. Say that
@strLocalConn = "DataSource = myFile.sdf; Password = whatever";

but @strLocalDbFile is "DataSource = SomeOther.sdf; Password = whatever";

You check for the existence of the second and delete it if you find it,
however, you aren't checking for the first (unless of course you are
positive they are the same file). Hence a
Debug.Assert(File.Exist("@strLocalConn")) might be helpful ...if you see a
big ugly assertion box, then that's not the problem, but if the assertion
doesn't fail, it means strLocalConn does exist and isn't letting you create
over it. In any case, having both is just going to be confusing and adding
an @ at the beginning is probably confusing too since that's the prefix for
SQL SErver parameters but these are just variables.
You can also assert (@strLocalDbFile == @strLocalConn) ; if this succeeds
then the strings match so the delete check you do will be valid, otherwise
it won't be.
Let me know if the Path in fact exists, and if the file exists, one of those
is probably the problem.
gfeighny said:
Keep getting error: SQL Server CE encountered problems in creating
the SQL
Server CE database. [,,,Connection string,,]
if (File.Exists(@strLocalDBFile))
{
File.Delete(@strLocalDBFile);
}
//-- create local database
SqlCeEngine engine = new SqlCeEngine();
engine.LocalConnectionString = @strLocalConn;
1 device
I have but not on others!
The local file name and database string are good, because they work
on
other devices
 
Back
Top