Re: SqlceException.SqlceException



Thanks a lot Darren,
First of all, i found the cause of the exception and corrected it, it was
caused by some sql syntax errors.
Also, regarding the first option concerning my project, i didnt understand
it well, can you explain it in more details please?
And which choice do you recommend me to adopt?
Thanks again.

"Darren Shaffer" wrote:

> Philip,
>
> I have written a drug interaction application for physicians and faced the
> same challenge in terms of deploying the initial SQL CE database. You
> basically have two options:
>
> 1. construct a 'starter database' with schema and lookup values in the
> database.
> add this to your Compact Framework project as content and deploy the starter
> db along with your app. the only challenge you face here is increased size
> of
> the deployment package and keeping the read-only drug data up to date.
>
> 2. when your app starts, if there is no database found, create one
> programmatically
> as you are doing. this incurs a performance penalty as all users will have
> a long
> wait time the first time they run your app (assuming you load any
> significant amount
> of lookup data).
>
> What I did was this: I placed all of my table creation (DDL) statements and
> lookup
> data into text files. I deployed these along with my app as content. A
> simple method
> in my app opened the file and executed each line of the text files (one SQL
> statement
> per line) on the database. I'd then delete these files from device once I
> was sure they
> were loaded into the db. Once I had the starter database created, I never
> created it
> again (unless schema changed), but rather created it on device, copied it
> into my
> CF project, deployed it with my app as content and then kept it up to date
> using
> web services when the device was docked (end of work day).
>
> --
> Darren Shaffer
> ..NET Compact Framework MVP
> Principal Architect
> Connected Innovation
> www.connectedinnovation.com
>
> "Philip Germanos" <PhilipGermanos@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> message news:230CF987-FF11-401C-A1AA-06236CF3E6A2@xxxxxxxxxxxxxxxx
> > Here's the code:
> >
> > using System;
> > using System.IO;
> > using System.Text;
> > using System.Data;
> > using System.Data.SqlServerCe;
> > using System.Collections;
> > using System.Windows.Forms;
> > using System.Data.Common;
> >
> > namespace MDR_FINAL
> > {
> > /// <summary>
> > /// Summary description for CreateDB.
> > /// </summary>
> > public class CreateDB
> > {
> >
> > public static void checkDB()
> > {
> >
> > string dbFile = "\\Program Files\\MDR_FINAL\\Drugs_db.sdf";
> >
> > SqlCeConnection conn = null;
> >
> > try
> > {
> > if (!File.Exists(dbFile))
> > {
> >
> >
> > string dbConn = "Data Source =" + dbFile;
> >
> > SqlCeEngine dbEngine = new SqlCeEngine(dbConn);
> > dbEngine.CreateDatabase();
> >
> > conn = new SqlCeConnection(dbConn);
> >
> > conn.Open();
> >
> > SqlCeCommand cmd = conn.CreateCommand();
> >
> > cmd.CommandText = "CREATE TABLE Generic_Drugs" +
> > "(Name ntext CONSTRAINT PK_Generic PRIMARY KEY," +
> > " Use ntext NOT NULL, Synonyms ntext DEFAULT N/A, " +
> > "P_R_F nvarchar(40) DEFAULT N/A, P_I ntext DEFAULT N/A, " +
> > "Lactation ntext DEFAULT N/A, Contraindications ntext" +
> > " DEFAULT N/A, W_P ntext DEFAULT N/A, A_R ntext DEFAULT N/A," +
> > " Overd_Tox ntext DEFAULT N/A, C_P450 ntext DEFAULT N/A, " +
> > "IncEffect_Tox ntext DEFAULT N/A, DecEffect ntext DEFAULT N/A, " +
> > "E_N_H ntext DEFAULT N/A, Stability ntext DEFAULT N/A, Mech_Action" +
> > " ntext DEFAULT N/A, PD_Kinetics ntext DEFAULT N/A, Dosage ntext " +
> > "DEFAULT N/A, Dietary ntext DEFAULT N/A, Admin ntext DEFAULT N/A, " +
> > "M_P ntext DEFAULT N/A, Ref_Range ntext DEFAULT N/A, Test_Inter " +
> > "ntext DEFAULT N/A, Patient_Info ntext DEFAULT N/A, Nurs_Implic " +
> > "ntext DEFAULT N/A, Add_Info ntext DEFAULT N/A, Dosage_Forms ntext " +
> > "DEFAULT N/A, Extem_Prep ntext DEFAULT N/A)";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "CREATE TABLE Brands(Brand_Name nvarchar(40), "+
> > "Country nvarchar(6)" +
> > ", Manufacturer nvarchar(30) NOT NULL, Generic_Drug ntext NOT NULL" +
> > " CONSTRAINT FK_Generic references Generic_Drugs(Name), "+
> > "CONSTRAINT PK_Brands PRIMARY KEY(Brand_Name, Country))";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "CREATE TABLE Therapeutics(Generic_Drug ntext CONSTRAINT
> > FK_Therap references " +
> > "Generic_Drugs(Name) ON DELETE CASCADE ON UPDATE CASCADE,
> > Therapeutic_Class
> > ntext," +
> > " CONSTRAINT PK_Therap PRIMARY KEY(Generic_Drug, Therapeutic_Class))";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "INSERT INTO Generic_Drugs(Name, Use, Synonyms,"+
> > " P_R_F, Dosage, Add_Info, Dosage_Forms) " +
> > "VALUES ('Abacavir, Lamivudine, and Zidovudine', 'Treatment of HIV "+
> > "infection (either alone or in combination with other "+
> > "antiretroviral agents)', 'Azidothymidine, Abacavir, and Lamivudine', " +
> > "'C', 'Oral: Adolescents and Adults: 1 tablet twice daily; "+
> > "Note: Not recommended for patients <40 kg. " +
> > "Dosage adjustment in renal impairement: Because Lamivudine"+
> > " and Zidovudine require dosage adjustment "+
> > "in renal impairement, Trizivir should not be used in patients "+
> > "with CLcr <=50 mL/minute. Elderly: Use with caution', " +
> > "'Tablet: Abacavir 300 mg, Lamivudine 150 mg, Zidovudine 300 mg')";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "INSERT INTO Brands VALUES "+
> > "('Trizivir', 'U.S.A', 'GlaxoSmithKline', 'Abacavir, Lamivudine, and
> > Zidovudine')";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "INSERT INTO Therapeutics VALUES "+
> > "('Abacavir, Lamivudine, and Zidovudine', 'Antiretroviral Agent, "+
> > "Reverse Transcriptase Inhibitor (Combination)')";
> >
> > cmd.ExecuteNonQuery();
> >
> > cmd.CommandText = "INSERT INTO Therapeutics VALUES "+
> > "('Abacavir, Lamivudine, and Zidovudine', 'Reverse Transcriptase
> > Inhibitor')";
> >
> > cmd.ExecuteNonQuery();
> >
> > conn.Close();
> >
> > }
> >
> > }
> >
> > catch(SqlCeException e)
> > {
> >
> > MessageBox.Show(e.ToString());
> >
> > }
> >
> > }
> >
> > }
> >
> > }
> >
> > In other words, i am creating 3 tables, one with 28 fields, one with 4
> > fields and one with 2 fields and some constraints and i am inserting some
> > data.
> > I am using this class in the main form of my window application, i call
> > checkdb( ) to check if the db has been created, if no i enter the method
> > and
> > do all the work if yes i skip the method and then the user can use the gui
> > to
> > search for info in the db.
> >
> > Other than the exception question, i want your opinion concerning this
> > project as a whole, in other words is this the right way to do the
> > following:
> > I want a window application with a db and the application manipulates the
> > db(just reads data), but the problem here is that i want it in the end to
> > be
> > a real project, in other words pharmacy students will install the app on
> > their device, so the problem is, how do i integrate the db creation within
> > the application, in other words, the db creation will run only the first
> > time
> > the application runs because i dont want to run it after because i will
> > have
> > the db, but the gui will run everytime the user runs the application. Is
> > there better ways to do this, other then creating a special class for the
> > db
> > creation in the same project and use that class in the main class?
> >
> > Thanks a lot.
> >
> > N.B: it is the first time i am doing mobile applications and the first
> > time
> > i am doing complete application(installable) and the first time i am
> > developing in .Net
> >
> >
> > "Darren Shaffer" wrote:
> >
> >> we're going to need more info Philip - can we see the code that is
> >> causing the exception and if the exception has major and minor codes,
> >> that would help figure out what's going on.
> >> --
> >> Darren Shaffer
> >> ..NET Compact Framework MVP
> >> Principal Architect
> >> Connected Innovation
> >> www.connectedinnovation.com
> >>
> >> "Philip Germanos" <PhilipGermanos@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> >> message news:5F97FC64-9373-4262-806E-C45ADECE80FB@xxxxxxxxxxxxxxxx
> >> >I am getting this exception when i deploy my project on the emulator, it
> >> >is
> >> > coming from a class in the project where i create the database, create
> >> > the
> >> > tables then insert some data. What could be the error here?
> >> > Is it a sql syntax error? or something regarding the classes involved
> >> > in
> >> > creating the database?
> >> > Thank you.
> >>
> >>
> >>
>
>
>
.



Relevant Pages

  • Re: SqlceException.SqlceException
    ... same challenge in terms of deploying the initial SQL CE database. ... db along with your app. ... it is the first time i am doing mobile applications and the first ...
    (microsoft.public.sqlserver.ce)
  • Re: JDBC and threads
    ... > hard time figuring it out. ... > The app shows a JTable that is filled with data from a database. ... I would like the exception to be thrown rather than ...
    (comp.lang.java.programmer)
  • Re: writable metakit file inside a starkit
    ... The proc above writes the data to the ... everything works as expected the first time I run the app. ... database, but it's not there. ...
    (comp.lang.tcl)
  • Re: why application with access database doesnt run
    ... If you are not getting an exception cause you are catching them, ... > application does not work because it has no database. ... > Does the fact the client doesn't have MS Access installed on his ... > should't this DLLs be enought for my app to work? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: exception pause
    ... > my app, there is about a 2 second pause. ... After that first time, ... > and doing this will always throw an exception if the class doesn't ... IMyInterface imyint = someclass as IMyInterface; ...
    (microsoft.public.dotnet.languages.csharp)

Loading