ASP.NET OLEDB code breaks when deployed on IIS7 - asp.net

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).

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.

Related

Reporting Services 2008 - 401: Unauthorized

I've an application that connects to Reporting Services in SQL Server 2008 R2.
The error is the following:
System.Net.WebException: The request failed with HTTP status 401: Unauthorized.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse
(SoapClientMessage message, WebResponse response, Stream responseStream,
Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke
(String methodName, Object[] parameters)
at Microsoft.SqlServer.ReportingServices2005.Execution.ReportExecutionService.LoadReport
(String Report, String HistoryID)
The application is running in production fine in 2 different customers, so it's not a codeing issue.
I'm trying to install it now on a customer's server, which is using AD. The SQL Server and the IIS is all in the same machine though, so I don't really care about AD.
It runs if I run IE as Administrator, but it doesn't work with other users. The ASP.NET app is connecting to SSRS using a user created in the local machine (called ReportingServicesUser), member of the ReportingServicesUser group.
Things I've tried:
Adding ReportingServicesUser to the Site Settings in the RS website (did the same for Network Service, IUSR, the Authenticated Users group, Local Service, etc)
Adding ReportingServicesUser to the folder permissions in the RS website (did the same for Network Service, IUSR, the Authenticated Users group, Local Service, etc)
Added permissions for that users to the databases (app database and RS related dbs)
Added NTFS permissions to the RS folders (I will double check though).
Connecting to the RS using http://localhost, http://computername and http://domain.com
For reference, the code is this (simplified version):
var service = new ReportExecutionService();
service.Credentials = new NetworkCredential("ReportingServicesUser", "password");
service.Url = "http://computername:90/ReportServer/ReportExecution2005.asmx";
service.ExecutionHeaderValue = new ExecutionHeader();
var execInfo = new ExecutionInfo();
execInfo = service.LoadReport("path-to-the-report", null);
===> Here it throws the exception
I've read a lot of posts and pages about this but I cannot get an answer that works for me.
OK, I've finally had to change the code to:
rs.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
and it worked. Probably there's another solution but I couldn't find it out.
Are you sure you gave "ReportingServicesUser" browse permissions for the specific report in ssrs? The request never made it to the server it seems but I would check \Reporting Services\LogFiles just to be certain.
Also, Your "report user" user needs to be defined on the reporting server with the credentials you send.

Why is this SQL connection in my ASP.NET page failing?

I have the following code
SqlConnection conn = new SqlConnection("user id=clearpath\\user;" +
"password=Password1;server=sqldatamart;" +
"Trusted_Connection=yes;" +
"database=LENDER_LOAN_SERVICE;" +
"connection timeout=30");
SqlCommand cmd = new SqlCommand("INSERT INTO [LENDER_LOAN_SERVICE].[CMC].[Turn_Times] values('"+dateadded+"','"+username+"','"+prevtime+"','"+type+"','"+newturntime+"')",conn);
conn.Open();
which works fine when I am doing local development. However when I put the website on my IIS 6 on my computer I get the following error.
Login failed for user 'CLEARPATH\IT-CARLOSDELL$'.
Line 42: SqlCommand cmd = new SqlCommand("CMC.sp_NewDocMod", conn);
Line 43:
Line 44: conn.Open();
Line 45:
Line 46: SqlDataReader reader = cmd.ExecuteReader();
with an error on line 44.
It seems its changing the connection string from clearpath\cpereyra to clearpath\IT-CARLOSDELL$
My computer name is IT-CARLOSDELL
any ideas on how to fix this?
Thanks
Sounds like your application pool is using 'LocalSystem' as pool identity.
You need to do one of the following:
Give permissions in SQL for the CLEARPATH\IT-CARLOSDELL$ account
Change the identity on the application pool to one with permissions in the DB (Perhaps clearpath\cpereyra)
Set up authentication on your site to impersonate the user who connected to the site and has rights in the SQL DB.
Remove Trusted_Connection=yes from your connection string.
Which one you pick depends on the approach you use to secure your site.
BTW: It is not changing the connection string. It is using that account because you have Trusted_Connection=yes. It is using the account the ASP.NET worker process is running under to try to connect to the database.
Remove the Trusted_Connection=yes from your connection string. Right now, the string is giving a specific user name and password and also saying to use the pass-through Windows authentication. When running locally, your Windows account has rights to SQL (I assume), but in IIS, it is most likely logging on as anonymous.

MSDataShape {Class not registered error} in Classic ASP

I am trying to build a datagrid in Classic ASP. I have read a few articles here and there and am trying to use MSDataShape to implement this.
I have never worked with MSDataShape, so have absolutely no idea about it.
'Create the ADO Connection object.
set oCon = Server.CreateObject("ADODB.Connection")
'--- Generate the connection string
sCon = "Data Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;"
sCon = sCon & "Data Source=" & Server.MapPath("Northwind.mdb")
oCon.ConnectionString = sCon
'--- Specify that we will use the Data Shaping provider.
oCon.Provider = "MSDataShape"
'--- Open the connection
oCon.Open
I get the following error:
Microsoft OLE DB Service Components error '80040154' Class not
registered /DG/test.asp, line 39 –
The error message indicates that the data provider you specified can't be found. In this case, 3.51 is a very old version of Jet. Try using the following:
sCon = "Data Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;"
Also, if you're on a 64-bit OS, make sure you configure your application pool to run in 32-bit mode.

The attempt to connect to the report server failed. ssrs reporting

Hi, I am having problem while connecting to ssrs report. My report is running successfully on the server and i am attaching screen shot of the report also.
Client Code:
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://nysa31:8080/Reports_MS2008");
ReportViewer1.ServerReport.ReportPath = "~/New Item";
ReportParameter[] Params = new ReportParameter[1];
Params[0] = new ReportParameter("EmployeeID", "990");
ReportViewer1.ServerReport.SetParameters(Params);
ReportViewer1.ServerReport.Refresh();
I am getting this error. The attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.]
The Report Server URL you have set seems to be the Report Manager URL.
Enter the Report Server URL to resolve the issue.
You may want to have a bit of a read about accessing SSRS via windows auth, e.g.:
http://praveenbattula.blogspot.com/2010/01/report-viewer-control-authentication.html
use
http://Nysa31:8080/Reports_MS2008
instead of
http://nysa31:8080/Reports_MS2008
and folder names must starts with Uppercase letter.
because \n and \r are new line charectors. path name mayn't work .

Adding a work item to TFS 2010 from ASP.NET app fails due to permissions

I'm working on an ASP.NET webforms app that will serve as a simple intake form to create work items in TFS 2010.
The app works correctly when I run it locally in debug mode--the submission completes and the work item is created.
When I publish the form to our dev server, it yellow screens and throws the following error:
[SecurityException: TF50309: The
following account does not have
sufficient permissions to complete the
operation: DOMAINNAME\SERVERNAME$. The
following permissions are needed to
perform this operation: View
collection-level information.]
In my code, I'm attempting to access TFS using a service account, and from what I can tell the service account is being used correctly when I run in debug mode.
Here's what my C# looks like:
string tfsServerUrl = "http://servername:8080/tfs";
string tfsProject = "Web Team Projects";
NetworkCredential tfsCredential = new NetworkCredential("ServiceAccountName", "password", "DOMAIN");
TeamFoundationServer tfs = new TeamFoundationServer(tfsServerUrl, tfsCredential);
tfs.Authenticate();
WorkItemStore workItemStore = new WorkItemStore(tfsServerUrl);
If I set a breakpoint at the tfs.Authenticate() line, the server object shows the service account name as the current user and IsAuthenticated = true.
The line in the exception that mentions SERVERNAME$ is what's stumping me. It's seems like IIS is deciding to try to access TFS with the app pool identity instead of the credentials that I'm explicitly supplying.
Our dev server is a Server 2008 box running IIS 7.
Any suggestions?
The TeamFoundationServer class is obselete. Have you tried using the TfsTeamProjectCollection (TFS 2008) or TfsConfigurationServer (2010) class instead?
string tfsServerUrl = "http://servername:8080/tfs";
System.Net.NetworkCredential tfsCredential = new System.Net.NetworkCredential("ServiceAccountName", "password", "DOMAIN");
TfsConfigurationServer tfs = new TfsConfigurationServer(new Uri(tfsServerUrl), tfsCredential);
tfs.Authenticate(); // You should be able to omit this
WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

Resources