-1

I'm new to the coding world and therefore this maybe a stupid thing. I have coded a SW that will copy files to local disk and run a specific CMD command. The paths are stored in a database on the internal server. All works great on my computer. The released version and the installer etc etc.

(even the program does what it should, I'm in shock...)

But when I use the setup on another computer it wont run. I can see it working and I have looked in the Event log and found this:

Application: EAC600Programing.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.InvalidOperationException

at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(System.Data.OleDb.OleDbConnectionString, System.Data.OleDb.DataSourceWrapper ByRef)

at System.Data.OleDb.OleDbConnectionInternal..ctor(System.Data.OleDb.OleDbConnectionString, System.Data.OleDb.OleDbConnection)

at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Object, System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection)

at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions, System.Data.Common.DbConnectionPoolKey, System.Object, System.Data.ProviderBase.DbConnectionPool, System.Data.Common.DbConnection, System.Data.Common.DbConnectionOptions)

at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionPoolGroup, System.Data.Common.DbConnectionOptions)

at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection, System.Threading.Tasks.TaskCompletionSource`1, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal, System.Data.ProviderBase.DbConnectionInternal ByRef)

at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1, System.Data.Common.DbConnectionOptions)

at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory, System.Threading.Tasks.TaskCompletionSource`1, System.Data.Common.DbConnectionOptions)

at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory)

at System.Data.OleDb.OleDbConnection.Open()

at Session.Broker.GetVersionFromDB(System.String)

at EAC600Programing.Main.Fill()

at EAC600Programing.Main..ctor()

at EAC600Programing.Program.Main()

Main.Fill is a function I use to fill inn the combo boxes with data from the database. It again uses a couple of functions (seen on youtube and read in stackoverflow about them) that connects to the database and gets data. (Broker is separated into its own class file) I do not have the competence to figure this out at the moment, so if anyone could help, would be great. PS. already checked if same .Net versions. They are the same. (big corp pc network, so all pc's are the same.) And yes, full network access on both pc's and users.

Broker b = new Broker();
    private void Fill()
    {
        combo_BootCOC.DataSource = b.GetVersionFromDB("BootCOC");
        combo_BootBMS.DataSource = b.GetVersionFromDB("BootBMS");
        combo_BootMCS.DataSource = b.GetVersionFromDB("BootMCS");
        combo_MainCOC.DataSource = b.GetVersionFromDB("MainCOC");
        combo_MainBMS.DataSource = b.GetVersionFromDB("MainBMS");
        if (cb_Compact.Checked)
        {
            combo_MainMCS.DataSource = b.GetVersionFromDB("MainMCSCompact");
        }
        else
        {
            combo_MainMCS.DataSource = b.GetVersionFromDB("MainMCS");
        }

    }

    public class Broker
{
    OleDbConnection connection;
    OleDbCommand command;

    private void ConnectTo()
    {
        connection = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = N:\Release\Electric Solution\1 Production\03 Tools\05 EAC600 Programming\DataBase.accdb");
        try
        {
            command = connection.CreateCommand();
        }
        catch (Exception)
        {

            throw;
        }
    }

    public Broker()
    {
        ConnectTo();
    }

       public List<double> GetVersionFromDB(string db)
    {
        List<double> versionList = new List<double>();
        try
        {
            command.CommandText = "SELECT * FROM " + db;
            command.CommandType = CommandType.Text;
            connection.Open();

            OleDbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                double v;
                v = Convert.ToDouble(reader["swVersion"]);

                versionList.Add(v);
            }
            return versionList;
        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
            }
        }
    }

EDIT1:

Soooo, i got rid of the first problem by installing Access 2010, and ended with this problem:

Application: EAC600Programing.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.FormatException

at System.Number.ParseDouble(System.String, System.Globalization.NumberStyles, System.Globalization.NumberFormatInfo)

at System.String.System.IConvertible.ToDouble(System.IFormatProvider)

at System.Convert.ToDouble(System.Object)

at Session.Broker.GetVersionFromDB(System.String)

at EAC600Programing.Main.Fill()

at EAC600Programing.Main..ctor()

at EAC600Programing.Program.Main()

So heading back in to see what i did wrong.

  • the other computer probably doesn't have the required drivers and/or oledb set up. Copy your OLEDB setup from your computer onto the target machine – Liam Aug 01 '18 at 11:52
  • Alos check you can access the data source as your using a mapped drive – Liam Aug 01 '18 at 11:53
  • I had a similar issue with OleDb and it was just a missing/old dll on the machine(s). OleDb depends on a series of dlls that are bundled with the C++ redistributable you can get off microsofts website. They also come with several other distributable packages including the Microsoft Access Database Engine Redistributable. I'd start there. – Hack Aug 01 '18 at 11:59
  • So, Installed a new SQL/OleDB Driver back, same result, same event log. Will restart and try again. Checked the data access. Full read access from other users. Full Write access from me. I am only one who is gonna write new pathways. C++ distro.... hmm gotta check that next. Thanx for feed back. – André Amish Holm Aug 01 '18 at 12:01
  • Path in your connection string is valid for that server? – nilsK Aug 01 '18 at 12:02
  • *Can* those other computers/users access ` N:\Release\Electric Solution\...`? – Hans Kesting Aug 01 '18 at 12:02
  • N:/Release is a read only for others in corp. Write access for me.. Admin rights to server. – André Amish Holm Aug 01 '18 at 12:03
  • So installed C++ redistributable 2017, as it was not installed, but no luck. I will continue looking for solutions, either not using OleDB or finding the correct driver pack. If anything else comes up il post. – André Amish Holm Aug 01 '18 at 12:17
  • Every user needs write access to that accdb file or maybe even it's containing folder. – Hans Kesting Aug 01 '18 at 12:34
  • Could you convert to a "real" database (SqlServer, MySql, ...)? Much safer than multi-user access to Access – Hans Kesting Aug 01 '18 at 12:35
  • @HansKesting I would if I could. :( Not enough experiance with coding, AT ALL. So this is my very first code written, and it works, for now. So when i get the chance to wrap my head around SqlServe, MySql i will. :P that was my original plan, but this worked as i wanted for this project. The DB is readable for all but only i have access (and admins). And again no one cares what I do. :P I learn as i go. Only way i know atm. – André Amish Holm Aug 01 '18 at 13:15

3 Answers3

0

To make your application work on any device with database connection.

1- The device that your application work on it should contain the DB.

2- your application should look for DB at the correct path.

To solve that problem :

-Move the connection string to app.config as the following

<configuration>
  <connectionStrings>
    <add name="ConnectionStringName" Provider = "Microsoft.ACE.OLEDB.12.0"; Data Source = "path_to_yourDB\DataBase.accdb"/>
  </connectionStrings>
</configuration> 

- call that connection string from your code as the following

var connectionString=ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;

if you want to move the application to another computer write the new path in the app.config instead of the old path.


Solution No 2: your can use relative path as the following link explain:

connection string with relative path to the database file

Muhammad Hassan
  • 475
  • 2
  • 14
0

I figured it out thanx to you guys. This is a small department SW and max 10 ppl will use so not that big of a deal.

All i needed was Microsoft Office Access 2010, witch all employees here have access to. The second problem was a bug where i converted a to a double that was a string that needed to be a string. (That was sooooo overlooked by me earlier).

I will look into better solutions in the future, but for now it works great on mine and 3 other computers and 3 other users with different user account permissions.

So I am happy as hell. Thanx you all for great help and tips. Looking forward helping (if i can) and being helped by you.

-1

You need runtime for you program. Runtime have to include all setup files which are needed for computer to run your software. In this case I think you need to include in your runtime:

  1. Microsoft .NET Framework 4

    https://www.microsoft.com/en-us/download/details.aspx?id=17851

  2. Microsoft OLE DB provider for Visual FoxPro 9.0

    https://www.microsoft.com/en-us/download/details.aspx?id=14839

I assure you when you install those on new computer that your app will work.

Shixx
  • 49
  • 7