Tuesday 22 September 2015

Login failed for user iis apppool default apppool System.Data.Sqlclient.Sqlexception

Introduction

I am here highlighting the issue System.Data.Sqlclient.Sqlexception:Login failed for user iis apppool \default apppool commonly encountering while working with ASP.Net application with IIS. I have been working on web application. Everything was going fine but suddenly I got the error“System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool’” and database connection couldn't open.

Error Description:

System.Data.SqlClient.SqlException was unhandled by user code:  Login failed for user 'IIS APPPOOL\DefaultAppPool

Below I have provided steps to resolve this issue.

Step 1: Go to Run (Win+R Shortcut) and then type “inetmgr” and hit “OK” button.
Step 2: Now you are in the IIS and now expand left pane and click on the “Application Pools
Login failed for user iis apppool
IIS (Application Pool)


Step 3: Now you can select “DefaultAppPool” and click on “Advance Settings”.

Step 4: Now open “Advance Settings” window and scroll down window to “Process Model”. Under the “Process Model” section select “Identity” property. Select “LocalSystem” from drop down list. "Local Service" works the computer on local system & over the local computer.

Application Pool Identity
Application Pool Identity
Step 5: Process Model Element was introduced with IIS 7.0 
Step 6: "ApplicationPoolIdentity" runs under dynamically created application pools. identity account. "ApplicationPoolIdentity" pool access the resources from "IIS AppPool\<AppPool>", It has the great feature to administrator who can impose security privileges to end users. This is run mostly for remotely or public accessing the website.

ApplicationPoolIdentity
ApplicationPoolIdentity

Step 7: Now Click on "OK" button, you have to take optional Step 4 or step 6 to run your application smoothly.

OK

Summary

Given above steps will provide you complete helpline, how to resolve the error of “Login failed for user 'IIS APPPOOL\DefaultAppPool’”. I hope it will work to resolve your problem perfectly.

Saturday 12 September 2015

Reading a word document using C#

We may have used FileStream to read text from a text file but not the same way for getting text from a word document.

We have to use a Microsoft COM component called "Microsoft Word 9.0 object library" which provides classes and methods to read from a word document.
We have to use Word.ApplicationClass to have access to the word application.

Open the word document in memory, copy all the content to the clipboard and then we can take the data from the clipboard.

The code required is given below:
Word.ApplicationClass wordApp=new ApplicationClass();
object file=path;
object nullobj=System.Reflection.Missing.Value;  
Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
                                      ref nullobj, ref nullobj, ref nullobj,
                                      ref nullobj, ref nullobj, ref nullobj,
                                      ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data=Clipboard.GetDataObject();
txtFileContent.Text=data.GetData(DataFormats.Text).ToString();
doc.Close();