سؤال

I'm trying to make a SQLite database but keep getting this exception when trying to create it.

Here's a picture of what's being thrown: https://i.stack.imgur.com/UEmIr.jpg

I was getting the same exception when trying to use finisar, but decided to try System.Data.SQLite and am still getting the same exception!

I think it has something to do with my App.config file but at this point, I'm completely clueless.

Here's my code just in case I'm coding something wrong. All help is greatly appreciated!

 public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        connectToSQLite();
    }

    private void connectToSQLite()
    {
        SQLiteConnection.CreateFile("ExamLog.sqlite");
        SQLiteConnection con = new SQLiteConnection("Date Source=ExamLog.sqlite;Version=3");
        con.Open();

        string sql = "CREATE TABLE EmpInfo (id int, firstName varchar(20), lastName varchar(20)";
        SQLiteCommand cmd = new SQLiteCommand(sql, con);

        cmd.ExecuteNonQuery();


    }

Thanks a lot!

----Edit per Dour High Arch's request----

Here's the exception detail:

System.Windows.Markup.XamlParseException occurred
  _HResult=-2146233087
  _message='The invocation of the constructor on type 'better.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
  HResult=-2146233087
  IsTransient=false
  Message='The invocation of the constructor on type 'better.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.
  Source=PresentationFramework
  LineNumber=3
  LinePosition=9
  StackTrace:
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
  InnerException: System.Data.SQLite.SQLiteException
       _HResult=-2147467259
       _message=SQL logic error or missing database
near ")": syntax error
       HResult=-2147467259
       IsTransient=false
       Message=SQL logic error or missing database
near ")": syntax error
       Source=System.Data.SQLite
       ErrorCode=1
       StackTrace:
            at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLite3.cs:line 1052
            at System.Data.SQLite.SQLiteCommand.BuildNextCommand() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs:line 380
            at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs:line 387
            at System.Data.SQLite.SQLiteDataReader.NextResult() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteDataReader.cs:line 1295
            at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteDataReader.cs:line 117
            at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs:line 805
            at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs:line 853
            at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteCommand.cs:line 838
            at better.MainWindow.connectToSQLite() in c:\Users\newAcc\Documents\Visual Studio 2013\Projects\better\better\MainWindow.xaml.cs:line 40
            at better.MainWindow..ctor() in c:\Users\newAcc\Documents\Visual Studio 2013\Projects\better\better\MainWindow.xaml.cs:line 28
       InnerException: 


Also, here's my App.xaml:

<Application x:Class="better.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

Thank you for all the help!

هل كانت مفيدة؟

المحلول

You have a misspelled "Data Source" as "Date Source". That is the reason XAML parser threw an exception when it run the constructor of your class.

Another error in create table statement with a missing closing parenthesis.

Corrections:

SQLiteConnection con = new SQLiteConnection("Data Source=ExamLog.sqlite;Version=3");

string sql = "CREATE TABLE EmpInfo (id int, firstName varchar(20), lastName varchar(20))";
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top