0

I made a project that uses a sqlserverce database for pricelist, emploee info etc, makes offer in PDF and opens new email to send it to client.

First problem was: "The specified table does not exist. [XXXXX]". I found out that if I run project as administrator it helps with connection with database.

But it causes other problem: runing project as administrator gives when Outlook is open (no problem when outlook is closed):

 System.Runtime.InteropServices.COMException Retrieving the COM class factory for component with CLSID ..... (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

when project tries to create new email.

Is there any workaround or way to make both pieces work together? Do you have any leads? I googled a bit but I learned that I have to change registry to avoid second problem. Is there any other way?

This is the code for email:

Outlook.Application objApp = new Outlook.Application();
              Outlook.MailItem mail = null;
              mail = (Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem);
              //The CreateItem method returns an object which has to be typecast to MailItem 
              //before using it.
              mail.Attachments.Add((object)saveFile.FileName, Outlook.OlAttachmentType.olByValue, 1, Type.Missing);
              //The parameters are explained below
              mail.To = email;
              mail.BCC = "someemailshere@something.pl";
              mail.Display();

This is code for database connection (happens few times in program):

 System.Data.SqlServerCe.SqlCeConnection sqlconnection = new System.Data.SqlServerCe.SqlCeConnection();
  System.Data.DataSet DtSet = new System.Data.DataSet();
  System.Data.SqlServerCe.SqlCeDataAdapter sqladapter;
  string katalog = Application.StartupPath + "\\Bazadanych.sdf"; //Data Source = C:\\Users\\user\\Documents\\Visual Studio 2010\\Projects\\BMGRP\\Oferty BMGRP\\Oferty BMGRP\\bin\\Debug\\BazaDanych.sdf

  sqlconnection.ConnectionString = "Data Source = " + katalog + "; Max Database Size=40"; //zmienić na katalog root programu
  sqlconnection.Open();

  string sql = "SELECT * From Przedstawiciele";
  sqladapter = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, sqlconnection);


  sqladapter.Fill(DtSet);
  comboBox1.DataSource = DtSet.Tables[0];
  comboBox1.DisplayMember = "imie";

  sqlconnection.Close();

Yes. The program installs in Program files as default.

Łukasz Motyczka
  • 1,169
  • 2
  • 13
  • 35

1 Answers1

0

Additional research shown that it is not possible to do what I wanted to do (run a project as administrator and create email when outlook is on). So only solution was to solve database problem: which is to install application in other folder then program files as @spender suggested. It helped.

Łukasz Motyczka
  • 1,169
  • 2
  • 13
  • 35