10 Replies - 3868 Views - Last Post: 12 July 2012 - 07:58 AM Rate Topic: -----

#1 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 10 July 2012 - 07:05 AM

Ok, I think Im missing something Big in programming logic when comes to web applications.
Once again Im clueless about how to proceed in the curent situation. I have a Bing Maps application that connects to a WCF Service to read and write to a database. In this application I have implemented reading from Shape file. Other than the geometry in the shapefile I am also reading the Info for the shapes that is contained in the DBF file. As I believe there is not a way to use database related libraries and operands in silverlight application, I have implemented the reading of the DBF in the Service. The thing is that when I try reading a shape file I get the error: "The ‘VFPOLEDB’ Provider is not registered on the local machine". Here is my code in the Service:



Is This A Good Question/Topic? 0
  • +

Replies To: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

#2 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 10 July 2012 - 07:13 AM

Damn me and the bad habit of using TAB. I am doing this for a second time ... I apologise, anyway here is the code:
  public DBFInfo ReadDBF(int zapis,string filepath, string filename)
        {
            DBFInfo result = new DBFInfo();

            int teku6tzapis = 0;
            string connectionstring = @"Provider=VFPOLEDB.1;Data Source=" + filepath + ";Extended Properties=dBASE III;";
            OleDbConnection connection = new OleDbConnection(connectionstring);
            OleDbCommand command = new OleDbCommand(@"Select * From " + filepath + @"\" + filename, connection);
            connection.Open();

            OleDbDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                if (teku6tzapis == zapis)
                {
                    result.ekatte = reader[3].ToString();
                    result.plost = reader[2].ToString();
                }
                teku6tzapis++;
            }

                
            connection.Close();
            return result;
        }


As I read in some posts the problem is that I do not have the driver installed. SO, I downloaded it from microsoft: http://www.microsoft...s.aspx?id=14839 , and installed it. Nothing changed... I see that there is a Mentioning of REGISTRATION of the specific driver, but I have absolutely no idea what that means, the instalation or some registration that has nothing to do with the instalation of the driver. I looked in its folder but I have nothing else but two readme files and an icon. I dont know how (if neccessery to register it). ANYWAY the interesting part is that I have written a simple application to test the reading from the DBF files. THe Irony is that I run the exe of that application on the server and opened a dbf file SUCCESSFULY... I have no idea how the reading works when using the simple application and WHY it does not when I call the service.
here is the code of the application - I believe them to be almost identical...(at some extend)
DataTable dt = new DataTable();
            try
            {
                string connectionstring = @"Provider=VFPOLEDB.1;Data Source=" + FileP + ";Extended Properties=dBASE III;";
                //string connectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileP + ";Extended Properties=dBASE IV;User ID=Admin;Password=;";
                OleDbConnection connection = new OleDbConnection(connectionstring);
                OleDbCommand command = new OleDbCommand(@"Select * From " + FileP + @"\" + FileN, connection);

                //string connectionstring = @"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=" + FileP + ";";

                //OdbcConnection connection = new OdbcConnection(connectionstring);
                //OdbcCommand command = new OdbcCommand("Select * From " + FileP + @"\" + FileN, connection);

                connection.Open();
                
                dt.Load(command.ExecuteReader());
                connection.Close();

                dataGridView1.AutoGenerateColumns = true;
                dataGridView1.DataSource = dt;
            }
            catch (Exception d)
            {
                MessageBox.Show(d.Message);
            }

So, I would appriciate if someone can tell me why I get this error when trying to read the dbf file in the service. I cant understand why it works fine in the test application and why it doesnt in the service. Some properties and security rights or something concerning the IIS or the service itself or what ... ? Thanks in advance guys.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3566
  • View blog
  • Posts: 11,079
  • Joined: 05-May 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 10 July 2012 - 07:29 AM

The .MSI should have taken care of registering the OLEDB driver in it.

After you installed the .MSI, what is the exact error you are getting when running as a service. Is it still "The ‘VFPOLEDB’ Provider is not registered on the local machine" ?

If so, the next couple things to check are:
- Make sure that you are setting your target CPU to x86 instead of AnyCPU.
- Make sure that the directory (and the ancestor directories) that has the actual database files has permissions to allow the IIS service access to the files.
Was This Post Helpful? 1
  • +
  • -

#4 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 12:00 AM

Ok, I tried setting the platform target in the build node in properties of the service to x86 and it was to Any CPU, but now the service doesnt even work... it gives me that error:
D:\Georgi\PUBLISH\TESTFOLDER\ServiceError.png
Also, I dont know how to give the directories that has the database files permissions to allow the IIS Service access to the files. The idea behind the application is that anyuser, from his own pc, from his home, can open a DBF file. Meaning that those files arent somewhere on the server machine...

Server Error in '/' Application.
Could not load file or assembly 'FirstWCFService' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'FirstWCFService' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Assembly Load Trace: The following information can be helpful to determine why the assembly 'FirstWCFService' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Stack Trace:

[BadImageFormatException: Could not load file or assembly 'FirstWCFService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +123

[ConfigurationerrorsException: Could not load file or assembly 'FirstWCFService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11568160
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167

[HttpException (0x80004005): Could not load file or assembly 'FirstWCFService' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11700896
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4869125

Because I see that the picture was not inserted, I guess I cant just import a file from my pc :)
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3566
  • View blog
  • Posts: 11,079
  • Joined: 05-May 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 12:21 AM

That last set of errors that you posted is a good indication that you are running 64-bit Windows with 64 bit IIS. It obviously can't load the 32-bit service. As I recall IIS6 had a way to get 32-bit web services running on 64-bit systems, but I don't know if the same is true of IIS7 and up.

Since the Visual Fox Pro OLEDB drivers that you want to use are 32-bit only, you'll need to find a way to run your webservice as 32-bits if you want to load those drivers.

Quote

The idea behind the application is that anyuser, from his own pc, from his home, can open a DBF file. Meaning that those files arent somewhere on the server machine...


Stepping back, though, I have serious doubts about the design of your webservice. I'm wondering how you plan on having a program that is running on a web server, go access a file that is sitting on somebody's home machine without their machine opening up their filesytem and somehow presenting it to the web server to treat as if it existed on the web server itself.
Was This Post Helpful? 1
  • +
  • -

#6 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 01:05 AM

About the 32bit part, yes the machine is 64 bits with IIS7. I will look for a way to run the service in 32bit mode, I hope that will finally get rid of the "driver not registered" error. I dont trully insist on using that driver perticulary , the whole process was that I had no idea how to read DBF files and I looked through internet. The first things I tried were using the Microsoft.Jet.OLEDB.4.0 in a connection string something like that:
string connectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileP + ";Extended Properties=dBASE IV;
However, this resulted in "Unexpected error from external database driver (8961)". I tried using odbc not oledb , so basically I tried 2 3 different ways I found suggested yet every single one of them gave me the 8961 driver error. So the only thing that worked was using the VFPOLEDB.
About the files, I am really new to programming and I am truly not aware what can and cant be done. Meaning that I have no idea if I can just load the file from a file dialog and hope it has gone to the service. I had the problem of not being able to read the dbf file in the silverlight client so I tried doing it with the service. And on my machine( that i write and run the visual studio) it all works fine. But I realize that I am far from familiar with the concepts that are in place when I actually publish that application, and the client server relationship.
In summary the whole proccess Im doing is as follows: (about the files): I am reading a ShapeFile that has .shp, .shx, .dbf files. I have a file dialog that opens in the silverlight client, and when I choose the file, the project reads the .shp file, and waits for the service to read the DBF. If there is a different and more correct way I would appriciate if someone can tell me. And if you can suggest some literature that concernes the mentioning proccess and concepts I would appriciate it.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3566
  • View blog
  • Posts: 11,079
  • Joined: 05-May 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 01:15 AM

You probably will have better luck with this code to read shapefiles: http://shapefile.codeplex.com/

It seems to also have some issues running on 64-bit machines, but apparently it's just a matter of getting the 64-bit version of Jet. More details at: http://shapefile.cod...m/documentation

(I've not actually used this code. I was just doing a Google search.)
Was This Post Helpful? 1
  • +
  • -

#8 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 01:27 AM

Thank you, I might give it a try, but I am wondering for the part that files must be ... I mean that ... the code to read the shapefile is in my Silverlight client. The code to read the dbf is in my service. They both Work fine when I do it on my local machine while running the application in the visual studio. The Filepaths that run the filestream for the shp reading and the oledb command in the service are taken from the file dialog. Does that type of proccess work? Meaning are the client and service capable of accessing the file and actually reading it when I am using the published application from a different computer. Does the file get loaded somehow or is there anything else I should do...
Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4479
  • View blog
  • Posts: 7,801
  • Joined: 08-June 10

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 11 July 2012 - 07:15 AM

By the way, Skydiver mentioned something about 32 bit assemblies running in IIS. There is a way to do this. You need to go into the advanced settings of the application pool that your application is running under.

Attached Image
Was This Post Helpful? 1
  • +
  • -

#10 astian  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 15-June 12

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 12 July 2012 - 02:57 AM

Thank you guys for trying to help me. After some time spent bashing my head in the desk, trying to figure out what I am doing wrong, I told to myselft "why use those stupid drivers and service for the reading of the file" (I may had used more strong language but anyway :), and decided to do a Binary reading of the DBF file. Using the specs I found in this site: http://www.dbf2002.c...ile-format.html I managed to write a simple algorythm that reads the dbf file using nothing other than filestreams. It is really Far from perfect, and Im skipping through a lot of the file, but I am only interested in the name and number of columns and the records themselves. So the programm reads the dbf binary and gets just that. I have posted the code of my way of reading a dbf file binary in my blog ( http://www.dreaminco...bf-file-binary/ ) if in some strange way it can help someone save some time. Thank you again for your responses and I am happy to inform that when implementing this in the client itself, the shapefile(along with the dbf ofcourse) opens and reads perfectly. So all is well when it ends well right :)
Was This Post Helpful? 1
  • +
  • -

#11 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4479
  • View blog
  • Posts: 7,801
  • Joined: 08-June 10

Re: Problems reading DBF Files in WCF Service - VFPOLEDB not registered...

Posted 12 July 2012 - 07:58 AM

We appreciate that you shared your solution with the community!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1