title: SQL Server CE - Database cannot be null
body: <p>I keep getting error on my WinForms application whenever I create new database and insert data.</p>
  
  <p>This is how I create the database</p>
  
  <pre><code>Public Function CreateDatabase() As String
      Dim ds As String = "Data Source=" + (My.Computer.FileSystem.SpecialDirectories.MyDocuments) + "\" + (Application.ProductName) + "\" + (DBName) + ".wv" + ";Persist Security Info=True;"
      Dim Conn As New SqlCeConnection(ds)
      Dim Cmd1 As New SqlCeCommand()
      Dim Cmd2 As New SqlCeCommand()
      Dim SqlCeDB As New SqlCeEngine(ds)
      Dim Msg As String
      Try
          If Not System.IO.File.Exists(DBName) Then
              Msg = "Database successfully created in " &amp; Application.StartupPath
              SqlCeDB.CreateDatabase()
              Cmd1.Connection = Conn
              Conn.Open()
              'Create acPassword Table
              Cmd1.CommandText = "CREATE TABLE [wvAccount](" &amp; _
                                  "[acName] [nvarchar](100) NOT NULL, " &amp; _
                                  "[acPassword] [nvarchar](100) NOT NULL," &amp; _
                                  "[acKeyFile] [nvarchar](64) NULL, " &amp; _
                                  "[acLastLogin] [nvarchar](100) NULL, " &amp; _
                                  "[acLastModified] [nvarchar](100) NULL)"
              Cmd1.ExecuteNonQuery()
              'Create pmPassword Table
              Cmd2.Connection = Conn
              Cmd2.CommandText = "CREATE TABLE [wvPassword](" &amp; _
                                  "[pmID] [int] CONSTRAINT pmID PRIMARY KEY NOT NULL, " &amp; _
                                  "[pmCat] [nvarchar](100) NOT NULL, " &amp; _
                                  "[pmTitle] [nvarchar](100) NOT NULL," &amp; _
                                  "[pmUsername] [nvarchar](100) NOT NULL," &amp; _
                                  "[pmSiteURL] [nvarchar](100) NULL," &amp; _
                                  "[pmNotes] [nvarchar](300) NULL)"
              Cmd2.ExecuteNonQuery()
          Else
              Msg = "There is already a Database with that name."
          End If
      Catch ex As Exception
          Msg = ex.Message
      End Try
      Return Msg
  End Function
  </code></pre>
  
  <p>And this is how I insert the data right after I create the database and populate with table</p>
  
  <pre><code>Private Sub ADD_PA()
      Dim StrSQL_vault As String = "INSERT INTO [wvAccount] ([acName], [acPassword], [acKeyFile], [acLastLogin], [acLastModified]) VALUES (@acName, @acPassword, @acKeyFile, @acLastLogin, @acLastModified)"
      classlibrary_vault = New ConnectionLibrary_Vault
      classlibrary_vault.openConnection_vault(strconnection_vault)
      If Not classlibrary_vault.isConnectionOpen_vault() Then
          Exit Sub
      End If
      classlibrary_vault.initializeCommand_vault(StrSQL_vault)
      classlibrary_vault.addParameter_vault("@acName", SqlDbType.NVarChar, txtName.TextLength, txtName.Text)
      classlibrary_vault.addParameter_vault("@acPassword", SqlDbType.NVarChar, txtEncryptedCode.TextLength, txtEncryptedCode.Text)
      classlibrary_vault.addParameter_vault("@acKeyFile", SqlDbType.NVarChar, txtKeyFile.TextLength, txtKeyFile.Text)
      classlibrary_vault.addParameter_vault("@acLastLogin", SqlDbType.NVarChar, txtLastLogin.TextLength, txtLastLogin.Text)
      classlibrary_vault.addParameter_vault("@acLastModified", SqlDbType.NVarChar, txtLastModified.TextLength, txtLastModified.Text)
      Try
          objcommand_vault.ExecuteNonQuery()
          txtAccountName.Text = txtName.Text
          'Set controls
          _Main.NotifyIcon.Visible = True
          _Main.NotifyIcon.ShowBalloonTip(1, Application.ProductName, VAULT_CREATED, ToolTipIcon.Info)
          Me.ParentForm.Controls.Remove(Me)
          controlManagePasswords()
      Catch ex As Exception
          DevComponents.DotNetBar.MessageBoxEx.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
      End Try
  End Sub
  </code></pre>
  
  <p>At first when I had a primary key on my <code>wvAccount</code> table, I experienced no problem but now I keep getting </p>
  
  <blockquote>
    <p><em>Database cannot be null, the empty string, or string of only
    whitespace.</em></p>
  </blockquote>
  
  <p>I have no problem creating the database, the only thing bothers me is when I try to insert a data on <code>wvAccount</code>. Btw, I'm using SQL Server CE 4.0 and VB.Net</p>
  
  <p>The <code>.wv</code> extension allows me to read and write on my database previously, so probably, there's no problem with that.</p>