Sharepoint SPSite - sharepoint-2007

I am trying to create a spsite of object for sharepoint search but i am getting exception in production as website not found
SPSite site = new SPSite("sitename");
ServerContext scon = ServerContext.GetContext(site);
SearchContext srchcontext = SearchContext.GetContext(scon);
Scopes sc = new Scopes(srchcontext);
It throws exception site not found i have checked the name of site it exixts.
Any Help??

Check that you are building against the correct target. I.e. x86 vs x64.
I get this error when I build against x86 and try and run against x64.

Do you have your permissions set up correctly? Check out this conversation...
http://social.msdn.microsoft.com/Forums/ja-JP/sharepointdevelopment/thread/4d923b6a-d423-4c42-82dd-3315872db9cc
You need to ensure (taken from the above) that:
The user is a server farm
administrator.
The user has Read and Write permissions on the content database.
The user is a site collection administrator.
The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.

You should also ensure that you are using an ip address you can hit from both your local box, and the server that you are running the program on.
Before executing the program, ping the webaddress from the cmd prompt.
Another way to test it is to open up the exact webaddress in a browser from the box that you are executing the program.
It's possible you are trying to hit an internal site from a server which is not on the same domain.
And finally, as it says in the MSDN Documentation you shouldn't be using "SiteName" but rather ensure that you are using "SiteAbsoluteUrl".

If you create a console application and try the same code there, the same code works. You have to add application to IIS and change the app pool identity. I did the same and it worked for me.

Related

Unable to access SQL table from appl running as service

I have a small test application, made with Delphi 10.3.1 as an Stand Alone HTTPSYS Intraweb service. It has an ADOConnection and a ADOTable and in FormShow of unit1, I open the connection, and the table and reads the first 10 rows and add them to a listbox. Just to see that it works and is possible.
When running the application as a Stand Alone HTTPSYS, vith visual GUI, it's working nicely, but when I compile it as a service, and install it, on the sql server, or on the development machine, it fails with access Violation, trying to open the table. I suppose it is an Authentication problem.
I have tried to open connection with both Windows Auth, and with a specific SQL login, and I have tried running the service with both local system (default) and with the specific SQL account.
What am I missing ?
The Specific SQL login, works in SSMS. I'm able to use it to login and access my tables.
Also, if I create the application as a DLL and put it on my IIS10, it works fine.
You are right. It has nothing to do with authentication.
For the IntraWeb HttpSys Stand Alone program to run as a service, the ServerController.ComInitialization property must be set to ciMultiThreaded.
Thanks for your comment which lead me to look elsewhere. You do deserve the credit.
Regards
Soren

Trying to call svn.exe from batch file called by .NET webpage - odd results

The situation: I have a mvc.net web page which, when called, runs a batch file on my server using System.Diagnostics.Process.Start and cmd.exe. The batch file contains a line that runs "svn.exe update myfilepath" and should therefore update the files on the server.
What's happening?
- the batch file is running, but the call to svn.exe does nothing, nor produces any error messages.
- if I run the batch file by double clicking, the svn command DOES run successfully.
I guess this is a security issue, but I'm no expert on this and I cannot make any headway.
The site is hosted on Windows Server 2008 R2 and the app pool is using the ApplicationPoolIdentity system. I have tried running the app pool as Network Service and also adding Network Service as a user that can Read/Execute to svn.exe.
Please help!
This could be proxy related. It's possible that you access the Internet via a proxy, but that the user profile for the app pool identity isn't configured like this. You may need to use a domain account that you can log on as in order to create a suitable user profile. You will also need to make sure IIS is loading the profile by ticking the appropriate option.
(Another possibility is that the working directory for the process you are starting is not set correctly to the root of your Subversion working copy. We've established this wasn't the problem in your case.)

Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent

I have been attempting to run a Unit Test in visual studio for an MVC Application and continuously getting the following error:
The URL specified ('http://localhost:21496/') does not correspond to a
valid directory. Tests configured to run in ASP.NET in IIS require a
valid directory to exist for the URL. The URL may be invalid or may
not point to a valid Web application.
The only advice around is to make sure you have a localhost address in the UrlToTest attribute like so:
[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:21496/")]
This however still doesn't run against IIS Express or IIS 7 on Windows 7 and when I delved into the event logs, found the following problem.
(QTAgent32.exe, PID 6976, Thread 15) WebSites.GetWebServer: failed to create AspNetHelper: Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The website metabase contains unexpected information or you do not have permission to access the metabase. You must be a member of the Administrators group on the local computer to access the IIS metabase. Therefore, you cannot create or open a local IIS Web site. If you have Read, Write, and Modify Permissions for the folder where the files are located, you can create a file system web site that points to the folder in order to proceed. ---> System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_WebServerOrdinal()
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_RootPath()
at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_PhysicalPath()
at Microsoft.VisualStudio.Enterprise.Common.AspNetHelperMan..ctor(Uri uri, BasicAuthCredential credential, Int32 frameworkMajorVersion)
at Microsoft.VisualStudio.TestTools.HostAdapters.WebSites.GetWebServer(String webServerName, WebServerType webServerType, String urlToTest, String pathToWeb, String webAppRoot, BasicAuthCredential credential, Context context, WebSiteConfigurationType webSiteConfigType, Origin origin)
The next step I took was to make sure the QTAgent32 always runs with administrative privileges, along with visual studio.
I am now at a loss and cannot think of anything else to try, so do hope someone can at least point me in some direction.
Thanks
The tests were created in a default ASP.NET environment. In order to test the controllers but without the need to run the web application, you must delete the following attributes before the test methods.
[HostType("ASP.NET")]
[UrlToTest("http://localhost:21496/")]
I ran into the same problem today (also at this thread). I had the same errors in my event log:
(QTAgent32.exe, PID 12348, Thread 61) WebSites.GetWebServer: failed to create AspNetHelper: Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The website metabase contains unexpected information or you do not have permission to access the metabase. You must be a member of the Administrators group on the local computer to access the IIS metabase. Therefore, you cannot create or open a local IIS Web site. If you have Read, Write, and Modify Permissions for the folder where the files are located, you can create a file system web site that points to the folder in order to proceed. ---> System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
That lead me to this blog post which seems to have resolved the issue.
I just needed to go to "Turn Windows features on or off" and add IIS 6 Management Compatibility and all four subcomponents. I'm running Windows 7 Home Premium which doesn't have the Windows Authentication option, but that didn't seem to be an issue. Give it a shot and see if that resolves the issue for you.

Using Workspace.PendAdd in IIS doesn't work

I'm trying the WorkSpace.PendAdd method under Microsoft.Teamfoundation.Client namespace to add the local folder to TFS, it works normally when i debug with VS2010, but it doesn't work if it's published to IIS. I also tried giving the full control to the folder, but still no effect. Any idea will be appreciated.
Check to see what identity the web app is running under. Does that ID have appropriate rights in TFS? If you're hosting on a web server that is not also your TFS application tier, you could also be running into the two-hop limitation of passing identity.
When you're running in debug mode, it is probably picking up your credentials, and since your machine counts as hop zero, there's no problem passing them on to the TFS application tier.
I found a solution after checking the versionControl NonFatalError event.
Before the calling to workspace.PendAdd, just call:
Workstation.Current.EnsureUpdateWorkspaceInfoCache(
_versionControl,
_versionControl.AuthenticatedUser);
(for some reason it's the only way the specific file folder path will be mapped when running in IIS)

How can I create a local user profile for the anonymous user of an ASP.Net MVC application under IIS 7?

I've been experimenting with ASP.Net MVC, and have come across a problem that is probably not specifically MVC related. But I cannot get the authentication in the default MVC application (the one created by the wizard when you create a new MVC project) to work properly under IIS 7 on Windows 7.
If I run under the Visual Studio environment, it works, but if I switch the settings to run under IIS instead, I get the following exception trying to submit the login or registration:
Failed to generate a user instance of
SQL Server due to failure in
retrieving the user's local
application data path. Please make
sure the user has a local user profile
on the computer. The connection will
be closed.
I believe that this is because the website runs under my own account in Visual Studio, but under the IUSR account in IIS. Google searches on the exception message have been unhelpful so far.
So, can one create a local user profile for the IUSR account? If so, how? Is there something else I should be doing to get the SQLExpress engine to work under the anonymous account in IIS 7?
I also tried configuring the IIS website to use my account, but since this is my home machine, my account doesn't have a password, and it appears that IIS won't let a website be configured to use an account without a password. Or, since this is my first experience with IIS 7, and configuration feels very different than IIS 5/6, I am just missing the right setting that will let me configure the account to use for anonymous access.
EDIT: Some additional information. If I empty the App_Data folder and try again from IIS, SQLExpress attempts to create my database and fails, but the exception message has further information with the following suggestions.
SQLExpress database file auto-creation
error:
The connection string specifies a
local Sql Server Express instance
using a database location within the
applications App_Data directory. The
provider attempted to automatically
create the application services
database because the provider
determined that the database does not
exist. The following configuration
requirements are necessary to
successfully check for existence of
the application services database and
automatically create the application
services database:
If the applications App_Data directory does not already exist, the
web server account must have read and
write access to the applications
directory. This is necessary because
the web server account will
automatically create the App_Data
directory if it does not already
exist.
If the applications App_Data directory already exists, the web
server account only requires read and
write access to the applications
App_Data directory. This is necessary
because the web server account will
attempt to verify that the Sql Server
Express database already exists within
the applications App_Data directory.
Revoking read access on the App_Data
directory from the web server account
will prevent the provider from
correctly determining if the Sql
Server Express database already
exists. This will cause an error when
the provider attempts to create a
duplicate of an already existing
database. Write access is required
because the web server accounts
credentials are used when creating the
new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user
profile. See the readme document for
details on how to create a local user
profile for both machine and domain
accounts.
I've pretty extensively confirmed that the first three suggestions have been satisfied. The fourth seems to be the cause of my problems, but I can't figure out how to do that. And although the suggestion claims there is a readme document that describes it, I have not been able to find that document.
I got this problem as well running under medium trust. The process that creates the database requires at least High trust. You can check this by looking in your Web.Config for
<trust level="TrustLevel" />
If there is no trust specified in your Web.Config, try adding it and set it to either Full or High. If this doesn't work, there is a machine.config in your IIS which you would need to modify.
That being said, the best route I have found to solve this is to just use aspnet_regsql.exe to create the necessary tables and then change the connection string in your Web.Config to look at it directly.
I solved "The directory 'LocalApplicationData' does not exist." error when running an SSIS package through an SQL Job by ensuring the SQL SSIS service and SQL Server Agent service were running under the same account as the swql job was set to use!
This in my case was a domain account.
Solution: Try UNINSTALLING any updates before you started experiencing the issue. I spent countless hours - wasted hours that I will never get back in my life - reading and following every solution possible without success. I uninstalled all SQL Server updates and now everything works fine.

Resources