Sign in to follow this  
kappa

[.net] Access a sqlserver from a webservice?

Recommended Posts

I am having a probblem with accesing a sqlserver that I have on my machine from a webservice I created. I use the following connection string:
SqlConnection thisConnection = new SqlConnection(
			@"Data Source='my ip';Integrated Security=SSPI;"+
			"Initial Catalog=Sommarjobb" );

and I keep getting the error SQL Server does not exist or access denied. why does this not work?

Share this post


Link to post
Share on other sites
I am stumped.

I get the following error when using that or localhost


Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\reference\2188d9a1\428de847\hash.web" is denied.
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.UnauthorizedAccessException: Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\reference\2188d9a1\428de847\hash.web" is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

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.

Stack Trace:


[UnauthorizedAccessException: Access to the path "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\reference\2188d9a1\428de847\hash.web" is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) +44
System.IO.StreamWriter.CreateFile(String path, Boolean append) +55
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) +49
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) +20
System.Web.Compilation.PreservedAssemblyEntry.WritePreservedSpecialFilesCombinedHash(Int64 hash)
System.Web.Compilation.PreservedAssemblyEntry.DoFirstTimeInit(HttpContext context)
System.Web.Compilation.PreservedAssemblyEntry.EnsureFirstTimeInit(HttpContext context)
System.Web.Compilation.PreservedAssemblyEntry.GetPreservedAssemblyEntry(HttpContext context, String virtualPath, Boolean fApplicationFile)
System.Web.UI.TemplateParser.GetParserCacheItemFromPreservedCompilation()
System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean fCreateIfNotFound) +148
System.Web.UI.TemplateParser.GetParserCacheItemWithNewConfigPath()
System.Web.UI.TemplateParser.GetParserCacheItem() +88
System.Web.UI.ApplicationFileParser.GetCompiledApplicationType(String inputFile, HttpContext context, ApplicationFileParser& parser)
System.Web.HttpApplicationFactory.CompileApplication(HttpContext context) +43
System.Web.HttpApplicationFactory.Init(HttpContext context) +485
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +170
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +414

Share this post


Link to post
Share on other sites
This is easy :)

The ASPNET account is the account that runs ASP.NET code for IIS. So when you use SSPI to connect, the ASPNET account has to have rights (be a valid login and user in MSSQL) in the database.

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this