Hi, for some reason I can read this file perfectly on my machine (.net framework 4.5 is installed)

But when I run it on one of the servers (.net framework 4.0 is installed), i can't get the file to even open.

 try
                    {
                        // Connect to the file with the clean data and extract the relevant information
                        using (OleDbConnection con =
                            new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + CardFileGeneratorOutput.ToString() + ";"
                                                + "Extended Properties='text;HDR=Yes;FMT=Delimited(,)';"))
                        {
                            using (OleDbCommand cmd = new OleDbCommand(string.Format
                                ("SELECT VisaMasterNbr, AmexNbr FROM " + CleanedNedAllTermFile.ToString() + ""), con))
                            {
                                try
                                {
                                    con.Open();
                                }
                                catch (Exception e) { Console.WriteLine("Error reading from {0}. Message = {1}", @"C:\alienoreports\3.txt", e.Message); }
                                // Bind data to tbl(datatable), store all data in a list using Lambda Expressions, write data to a new CSV file. 

                                using (OleDbDataAdapter adp = new OleDbDataAdapter(cmd))
                                {

                                        using (DataTable tbl = new DataTable("MyTable"))
                                        {
                                            adp.Fill(tbl); // bind data to a datatable to keep it in memory for faster execution/processing
                                            List<string> VisaMasterNbr = tbl.AsEnumerable().Select(x => x[0].ToString().PadLeft(10, '0')).ToList();// pad values and store it in a list
                                            List<string> AmexNbr = tbl.AsEnumerable().Select(x => x[1].ToString().PadLeft(10, '0')).ToList();// pad values and store it in a list

                                            index = 0;
                                            StringBuilder sb = new StringBuilder();
                                            foreach (string part in VisaMasterNbr)
                                            {// write the relevant information to a result file.
                                                sb.Append(VisaMasterNbr[index] + ',' + AmexNbr[index] + Environment.NewLine);
                                                index++;
                                            }
                                            File.WriteAllText(VisaMasterAmexNumbers.ToString(), sb.ToString());
                                        }
                                    }

                                }

Recommended Answers

All 11 Replies

It seems like a no-brainer to develop using the .NET version that you plan on using to run the program, because new features are added in newer versions. Either install .NET 4.5 on the server, or install the .NET version you plan on using to run the program, on your development machine and use that version for your program (v4.0).

I targeted .net v4.0 on my machine.
I don't get why I can't open my oledb connection.

Are you running the actual program on the server, or running the program on your computer and trying to access the file on the server?

I developed it on my PC. Ican access the server if I want to but I copied the folder structure in exactly the same way that it is on ther server.

All in all, if it runs on my pc, it works perfectly.

Taking my exe file overto the server, the application bombs out at:

try
{
     con.Open();
}
catch (Exception e)
{
Console.WriteLine("Error reading from {0}. Message = {1}", @"C:\alienoreports\3.txt", e.Message);
}

The exception message wouldn't display on my machine because there are no problems on my machine.

On the server, "3.txt" is created but there is no information in the text file either as per e.Message.

Check the event logs on the server to see if there are any errors. Also add the following Catch (OleDbException e).

Also check that "Jet 4.0" is installed (properly).

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\OLE DB Provider"

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\InprocServer32"

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\ProgID"

  • reg query "HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers" | find "Microsoft Text Driver"

Adapted from here.

Also, ensure that your program is compiled only for x86 (not anyCPU). I don't believe that there is a 64-bit version of JET.

Get information about the computer (architecture and OS version):

            if (System.Environment.Is64BitOperatingSystem == true)
            {
                Console.WriteLine("Processor Architecture: 64-bit");
            }//if
            else
            {
                Console.WriteLine("Processor Architecture: 32-bit");
            }

            Console.WriteLine("OS Version: " + System.Environment.OSVersion.ToString());

Alternatively,

In a "cmd.exe" window,

OS version:
* reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v ProductName

Architecture:
set | find /i "architecture"

Thanks, I will try this at work tomorrow. The server is 64 bit though.

Hi, I see that Jet 4.0 is not properly installed.

Is there any other way that I can get 2 coloumns out of a csv file without this method?

Hi thanks a lot. The problem is that I had to target x86 as well. Jet seems to be working fine now, eventhough it is a 64 bit machine.

Glad to hear it is working. The registry keys above are for Win 7. They may be different on different OS's.32-bit applications can run on 64-bit machines. However, 64-bit applications can't run on 32-bit machines.

There is a correction to my above post. There was a typo. Also, the previously mentioned keys are for XP/Win 7 (32-bit). If you are using Win 7 (64-bit), you need to look in the "Wow6432Node"--since Jet 4.0 doesn't have a 64-bit version (Jet 4.0 only exists in a 32-bit version). These keys may also be found in MS server verions. Open a "cmd.exe" window, and run the following commands.

OS:

  • reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v ProductName

or using wmic:

  • wmic os get caption

Architecture:

  • set | find /i "architecture"

or using wmic:

  • wmic cpu get DataWidth

Jet 4.0:
reg query "HKCR\Microsoft.Jet.OLEDB.4.0"

32-bit operating system:

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\OLE DB Provider"

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\InprocServer32"

  • reg query "HKCR\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\ProgID"

  • reg query "HKLM\Software\ODBC\ODBCINST.INI\ODBC Drivers" | find /i "Microsoft Text Driver"

64-bit operating system:

  • reg query "HKCR\Wow6432Node\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\OLE DB Provider"

  • reg query "HKCR\Wow6432Node\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\InprocServer32"

  • reg query "HKCR\Wow6432Node\CLSID{dee35070-506b-11cf-b1aa-00aa00b8de95}\ProgID"

  • reg query "HKLM\Software\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers" | find /i "Microsoft Text Driver"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.