views:

106

answers:

2

I'm trying to write a simple website (ASP.NET v4), which will call Windows Search, find a specific file and return it to the user. I've put together the following as an example: it calls the Windows Search service on "remoteserver", and returns the path of "somefile.txt":

OleDbConnection conn = new OleDbConnection();

conn.ConnectionString = "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';";

OleDbCommand cmd = conn.CreateCommand();


cmd.CommandText = string.Format(
            "SELECT System.ItemPathDisplay, System.ItemType FROM " +
            " sytelhp.systemindex WHERE SCOPE='file://remoteserver/archive' AND CONTAINS(\"System.FileName\", " +
            " '\"*{0}*\"')", "somefile.txt");


conn.Open();

OleDbDataReader rdr = cmd.ExecuteReader();

string result=rdr[0].ToString();

.. and this works great on Visual Studio 2010 development environment, "result" contains the path to the file. However, if I deploy it to the local IIS7 server (running on Server 2008), I get this error:

The parameter is incorrect. 
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.Data.OleDb.OleDbException: The parameter is incorrect.

I'm at a loss where to go next. What do I need to do to IIS7, or the code, or both to get it working? Again, this works fine within VS2010 (tested on both Windows 7 and Windows 2008 Server).

+2  A: 

I guess you are running on Vista or older OS and the IIS runs on 2008 Server or newer? Try Provider=Search.CollatorDSO.1 (note the .1).

Edit: You should use a different user account for the search to work (not the default "network service" one the asp.net app runs under). See the comments for more info.

Jaroslav Jandek
I've tried running the code in Visual Studio 2010 running on both Windows 7 and Server 2008, and it runs fine on both. It's only when deploying it to the IIS on Server 2008 that it falls over. I've tried changing the Provider string (thanks), but it stills gives the "parameter is incorrect" error :(
Kenny Anderson
Provider=RSSearch.CollatorDSO.1;Extended Properties="Application=RSApp"If it does not work, then it might be a problem of the IIS user (running the app) not having a user profile (which would be a strange solution IMHO for a web application). The default account is a network service account.
Jaroslav Jandek
Of course! It's the account that the code's running under that's the problem. I've added code to impersonate a user, and using a domain admin account it's now working fine. Question is, as I don't really want the code to be running as a domain admin, what permissions or privileges does the account the code's running as need to access the remote Windows Search database?
Kenny Anderson
Empirically, using an account you can successfully **login** to the searched machine's desktop.You have mensioned you are using a remote query - I had to share the folders I queried to my account (even for administrator) for the search to return results successfully on the remote machine.
Jaroslav Jandek
A: 

This is not an answer, but can either of you help me with this post :) I think it is very close to what I am looking for:

http://forums.asp.net/p/1612663/4124040.aspx#4124040

Thanks, Robert Janisch

Robert Janisch