Posts filed under ‘ASP.NET’

Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’

Few days back,I developed an ASP.NET website in .NET 2.0 with SQL Server 2005 as the back end.ย  Everything was working fine in the cassini (web server that comes with VS 2005).

After finishing the project, for the testing purpose I thought of publishing it in the real IIS in my local machine.

All went smoothly ๐Ÿ™‚ and I was able to view the website locally, but when was I trying to login into the website with the administrator username and password I got something like thisLogin failed for user ‘NT AUTHORITY\NETWORK SERVICE'”

For some reasons I couldn’t understand why this is happening…. But after a googling I found that, this is because of the connectionstring that I used in the web.config ๐Ÿ™‚

If you have created the connectionstring, like below

<add name=”xxxxx” connectionString=”Datasource=servername;Integrated Security=SSPI;initial catalog=xxxx;”
providerName=”System.Data.SqlClient” />

ie you are trying to login into the SQL Server DB using the Integrated Secrity credentials which wrong ๐Ÿ™‚

So you have to explicitly specifiy the user id and password in the connectionstring, like below,

<add name=”xxxx” connectionString=”Data Source=localhost;Initial Catalog=xxx;user id=[userid];password=[password];” providerName=”System.Data.SqlClient”/>

Hope this will solve your issue

October 16, 2007 at 2:33 pm 14 comments

Nested Gridview to show Master/Details relationship in ASP.NET 2.0

This will help you to nest grdiviews inside ASP.NET. There may be many ways to do this, but this is my way( May not be the best, let me know if you have any other ๐Ÿ™‚ ).

1. First drop a gridview in to the page, also set its DataKeyNames to your primary key

2. Add a new template column to this gridview.

3. Place another gridview inside this template column.

the code for the termplate column may look like this

<asp:TemplateField HeaderText=”Heading”>
<EditItemTemplate>
<asp:TextBox ID=”TextBox3″ runat=”server”></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:GridView ID=”GridView1″ runat=”server” DataSource='<%# GetTrasnl(Convert.ToInt32(Eval(“pId”))) %>’ AutoGenerateColumns=”False” CellPadding=”4″ ForeColor=”Black” GridLines=”Vertical” BackColor=”White” BorderColor=”#DEDFDE” BorderStyle=”None” BorderWidth=”1px”>
<FooterStyle BackColor=”#CCCC99″ />
<Columns>
<asp:BoundField DataField=”language” HeaderText=”Language” />
<asp:BoundField DataField=”uName” HeaderText=”Translator” />
</Columns>
<RowStyle BackColor=”#F7F7DE” />
<SelectedRowStyle BackColor=”#CE5D5A” Font-Bold=”True” ForeColor=”White” />
<PagerStyle BackColor=”#F7F7DE” ForeColor=”Black” HorizontalAlign=”Right” />
<HeaderStyle BackColor=”#6B696B” Font-Bold=”True” ForeColor=”White” />
<AlternatingRowStyle BackColor=”White” />
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>

This child gridview has to show the content based on the primary of the row thats binded to main gridview.

Here in my case “pId” is the primary key. The nesting happens here

<asp:GridView ID=”GridView1″ runat=”server” DataSource='<%#GetTrasnl(Convert.ToInt32(Eval(“pId”))) %>’

what I have done is that, I have called function “GetTrasnl” and passed the primary key to that function. This function will return a datatable. So each time a row is bound to the main gridview, the child gridview is also bound with the corresponding values.

The functions is like this

Public Function GetTrasnl(ByVal prgId As Integer) As DataTable

………………
……………….

End Function

Please post your comments if you have any

July 26, 2006 at 5:02 am 32 comments

Sending Emails from ASP.NET 2.0

Sendingย  Emails from ASP.NET is very easy. In .NET 1.1 and 1.0, the class was System.Web.Mail but in .NET 2.0, they changed to System.Net.Mail.

The code for sending anย  email is given below

VB.NET

Dim email As MailMessage
Dim mailClient As SmtpClient

email = New MailMessage(fromAdd, toAdd, subject, message)

‘if you want to send HTML message set this property to true
email.IsBodyHtml = True

mailClient = New SmtpClient(“Your mail server name”) ‘like mail.xxx.com

‘ if your server is using different port then set this
mailClient.Port = [PortNumber]

mailClient.Send(email)

Some times your outgoing SMTP server may need username and password. Then you need to modify the code little bit.

First create an object of NetworkCredential (This is available in the System.Net Namespace) with the username and password

Dim authInfo As New NetworkCredential(smtpUsername, smtpPassword)

Then set the UseDefaultCredentials property of the smtp client object to false and set the Credentials property of the smtp client object to authInfo. Then send the mail.

mailClient.UseDefaultCredentials = False
mailClient.Credentials = authInfo

July 18, 2006 at 5:54 am 1 comment

Debugger Fails to Hit the Breakpoint When You Debug an ASP.NET Web Application

Today morning I was trying to debugg an WebApp, this application was running without any problem in laptop. But when I copied this to my PC and tried to give a break point, I was not able to bebug application. After googling I found many solutions. They are

1) This is from Microsoft

To resolve this issue, you need to force a reload of the pertinent .dll file into aspnet_wp.exe (or w3wp.exe for applications run on IIS 6.0). To do this, recompile the project before you debug again. However, the project cannot be recompiled unless you make changes to the code. Therefore, restart Microsoft Visual Studio .NET, and then click Rebuild All. (Alternatively, you can run the iisreset command from the command prompt.) Now, when you run the debugger again, it hits the breakpoint.

2) Second one is from a forum(I don’t remember the link).

If your application is having same file names(in my case Default.aspx, one inside the root folder and other inside the admin folder), this will issue will occur. So rename any one of these file and rebuild.

Actually I tried the first solution but no hope.

The second solution worked for me. Sometimes the first solution works for you. Try both.

These are bugs in the VS.NET. So don’t think this as your fault.

July 15, 2006 at 5:56 am 1 comment

How to check whether a file exist or not

There is method which makes it easy to check whether a file exist or not,

Code is given below

C#

if(System.IO.File.Exists(@”c:\test.xml”))

{

//True statements comes here

}

This code check whether a file named “test.xml” exist in the C:\ drive.

July 13, 2006 at 8:00 am 3 comments

An open-source ASP.NET menu server control

skmMenu is a simple and free ASP.NET menu server control. It uses XML file as back end. Really cool control.

Visit skmMenu website

July 11, 2006 at 6:36 am 3 comments

ASP.NET: Connection Strings

In ASP.NET there are several options for storing connection strings. These include the Web.config file, Application variables, custom text files, and hardcoded into pages or components. In Classic ASP, it was common practice to use the Application object to store the connection string information for an application, so it was common to find code like this in the global.asa file:

Sub Application_OnStart
	Application("Conn1_ConnectionString") = _
	"Provider=SQLOLEDB.1;UID=sa;PWD=p;Initial
		Catalog=src;Data Source=localhost;"
End Sub

This was the “best practice” approach for many websites. Another option that some sites, such as ASPAlliance.com, used was to have these settings in a common text file that was then called with Server.Execute, such as this:

Sub Application_OnStart
	Server.Execute "/db/config.asp"
End Sub

This would allow many different applications (like all of the individual columnists on ASPAlliance.com) to have their connection information stored in one place. ASPAlliance also used a COM object’s property for this same purpose for a while. The question is, what’s the best way to store this information in ASP.NET?Well, there is no single right answer for this question, but depending on your situation, there is usually a method that is best. Before we consider the different possibilities, let’s consider one option that should probably be eliminated right away: Application variables.

(more…)

July 11, 2006 at 5:06 am 1 comment


Top Clicks

  • None

Calendar

June 2017
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
2627282930  

Recent Posts

Feeds

Blog Stats

  • 92,980 hits