Monday, March 12, 2012

How to Handle Error Message: "Login failed for user (null). Reason: Not associated with a

I'm running WinXP and using "Visual Studio 2005". To make a long story short, my "Default.aspx" page is using a GridView to display data which is being read from a Windows 2000 DB server. When I run the app under the IDE all works fine.

I copied the 1 file and put it into my folder as, "C:\Inetpub\wwwroot\default.aspx". When it loads I receive the error message, "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection."

I'm frustrated with Studio Express 05 and will not bother with it again until Microsoft fixes this deployment issue. Can any one PLEASE help me???As you surely understand, this is a question of Access Premissions. When you write "Windows 2000 DB server", do you actually mean SQL 2000 Server? Assigning permissions correctly to the '<machinename>\ASPNET' account can be a bit difficult to grasp sometimes. It would help if you described your exact setup (what is installed on which machine). Example:
- Asp.Net 2.0 version 2.xxxxxxxxxx installed on machine YYYY running OS Windows XP Pro with 'IIS X.X'
- SQL Server version XXXX running on machine ZZZZ running OS QQQQ.

swep wrote:

I'm frustrated with Studio Express 05 and will not bother with it again until Microsoft fixes this deployment issue. Can any one PLEASE help me???


Your error SCREAMS "bad/improper connection string", so i wouldn't be so quick to blame a "deployment issue"
Application created on (my machine):
- Asp.Net 2.0 version 2.0.50215.44 running OS Windows XP Pro SP 2 with 'IIS 5.1'

Accessing database on:
- SQL Server 2000 Enterprise Edition running OS Windows Server 2000.

I'm really stuck...Any help you can offer would be greatly appreciated.
You must put in a valid connection string, because that is what the error is telling you
http://www.connectionstrings.com

I'm really lost right now and need some expect advice. You mentioned in the ASP.NET forum,

"You must put in a valid connection string, because that is what the error is telling you"

If my connection string is wrong then why can I connect to the db server within Visual Web 2005 just fine? My web.config file contains my connection as,

add name="WebConnectionString" connectionString="Data Source=NAME OF SQL SERVER;Initial Catalog=NAME OF TABLE;"

Could it be that I created this in .net framework 2.0 and it is querying a database in the .net framework 1.1?

hello.

maybe the problem is related with the fact that the asp.net user hasn't enough permissions to access the database (you might not have faced this problem because when you use the internal server it'll use the credentials of the active user to process the request - this does not happen when you use IIS: in this case, i't use a specific account for accessing the db).

Labels: , , , , , , , , , , , , , , , , , , ,

How to handle dynamic control event in repeater?

Hello!

I've met with a problem. I'm building a list of products and use asp.net repeater to display it. each item has to have a LinkButton called "Remove" and I need to handle the click event somehow... :(

Any ideas how to insert a linkbutton into repeater item in a way so I can handle the click event it in the code for all of them?


Put the link button in the repeater

<asp:LinkButton ValidationGroup="Delete" ID="LinkButton1" CommandArgument='<%# Eval("myID") %>">' runat="server" CausesValidation="True"
CommandName="Delete" Text="Delete" OnClick="LinkButton1_Click"></asp:LinkButton>

protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
String idtoDelete = btn.CommandArgument;
// Run Delete
}

Labels: , , , , , , , , , , , , , ,

How to handle data in different tables?

I was wondering if someone could point me to a tutorial that might help me?

I have an application that I'm developing that will display a tabbed form which needs to contain data from different tables. For example, my database has a contact table with typicall information and then it also has a lead table which contains information if the contact is a sales lead. They are linked together by a common contactID column. There are a few other normalized tables also like an AlternateAddress table.

My first problem was that I could only get the binding source to connect to a particular table. This was a problem cause the data that I need to modify is normalized across a few different tables. My solution to that problem was to create a view and join all of my data from the different tables into a 'virtual table'.

My new problem now is I can't generate an update command for a view.

How do I get a binding navigator to use a binding source to navigate through my data for each contact and also be able to update changes to the datasource?

I've read some other posts about this (there's not many) and here's what I think might work. Can someone tell me if there is an easier way?

I would have my dataset with a table for each table in the database (ContactInfo, Lead, and Alternate Address) Each would have a table adapter, but the Lead and Alternate Address tables would have an additional table adapter to fillByContactID. I would have my binding source tied to my contactInfo table, and I would have to catch the position changed event and then re-fill the Lead and Alternate Address tables by the current contactID.

Would it be easier to write my own update function for using a VIEW? Someone please help. Thank you.


create a view in sql server

allow the application to update insert delete from the view

in sql server configure an instead of update,insert and delete trigger

that updates individual table behind the scene


From what I understand, I can't update to a view without writing my own update SQL command correct?

yes you can write your update statement for a view

but inside sql server it can be the instead of triggers

that update the individual base tables behind the scene

most views are not updateable. VS perceive the view as updatable


Adam,

ADO.NET 2.0 is not very apt at dealing with scenarios involving multiple tables. I know it sounds silly, but this is unfortunately the truth. LINQ to SQL and ADO.NET vNext deal with this problem out of the box.

So obviously the question is, "What can you do to deal with this problem today".

The best answer I can give you is to do some further reading into ADO.NET and try and wean yourself away from drag-drop solutions for this problem. A handwritten solution, which is definitely possible in ADO.NET 2.0 (my book covers it well in Chap 10), is your best bet in this scenario.

The "virtual table" scenario you mention - may just be a good shortcut, but you will probably have to hand-specify your own commands.

- Sahil Malik
http://blah.winsmarts.com


I found the answer I was looking for. Basically I followed this example which showed me that the way to have multiple tables on the same form is to have multiple binding sources and then hooking the Data Source of the child tables up the Parent table binding source. Also, hook the Data Member of the child tables up to the Foriegn Key in the parent table's binding source. Anyone else looking for help with this, follow this example and then look at the binding sources.

http://msdn2.microsoft.com/en-us/library/4esb49b4.aspx

Labels: , , , , , , , , , ,

How to handle Checkbox in itemtemplate and with the button in gridview

Hi All

I m having a gridview,button control on a form. In thatPatientId is a templatefiled along with a check box.Per page i m goingto display 10 records of a same patient.

My requirement is

1.user has to select only one check box if user selects more than one check box alert or message should be displayed.

2. If user checks only one checkbox i have to pick the particual row. I want to store all the values.

How to handle it.

I m able to get the values with checkbox, but i m unable with the button .

Here is my aspx page code

<asp:GridView ID="Prescgrid" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None"
BorderWidth="1px" CellPadding="4" Height="49px">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Refill"
Text="Refill"></asp:LinkButton>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Patient_id" SortExpression="patient_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("patient_id") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("patient_id") %>'></asp:Label>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack=true OnCheckedChanged="Hai" />
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="prescription_date" DataFormatString="{0:d}" HeaderText="Prescription Date"
HtmlEncode="False" SortExpression="prescription_date">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="home_phone" HeaderText="Patient Home Phone" SortExpression="home_phone">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="pharmacy_phone" HeaderText="Pharmacy Phone" SortExpression="pharmacy_phone">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="medication1" HeaderText="Medication" SortExpression="medication1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="dosage1" HeaderText="Dosage" SortExpression="dosage1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="frequency1" HeaderText="Frequency" SortExpression="frequency1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="refills" HeaderText="Number Of Refills" SortExpression="refills">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="amt_tablets" HeaderText="Number Of Tablets" SortExpression="amt_tablets">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="staff_comments" HeaderText="Staff Comments" SortExpression="staff_comments">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
nbsp;

<asp:Button ID="Button1" runat="server" Text="Button" />

Waiting for valuable replies

Thank u

Baba

Hi Baba,

Now you want to capture the GridViewRow on which the CheckBox is selected on ButtonClick, right?

Try this.

<asp:GridViewID="Prescgrid"runat="server"AllowPaging="True"AllowSorting="True"

AutoGenerateColumns="False"BackColor="White"BorderColor="#3366CC"BorderStyle="None"

BorderWidth="1px"CellPadding="4"Height="49px">

<FooterStyleBackColor="#99CCCC"ForeColor="#003399"/>

<Columns>

<asp:TemplateFieldShowHeader="False">

<ItemTemplate>

<asp:LinkButtonID="LinkButton1"runat="server"CausesValidation="false"CommandName="Refill"

Text="Refill"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Patient_id"SortExpression="patient_id">

<EditItemTemplate>

<asp:TextBoxID="TextBox1"runat="server"Text='<%# Bind("patient_id") %>'></asp:TextBox>

</EditItemTemplate>

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

<ItemTemplate>

<asp:LabelID="Label1"runat="server"Text='<%# Bind("patient_id") %>'></asp:Label>

<asp:CheckBoxID="CheckBox2"runat="server"AutoPostBack="true"OnCheckedChanged="CheckBox2_CheckedChanged"/>

</ItemTemplate>

</asp:TemplateField>

<asp:BoundFieldDataField="prescription_date"DataFormatString="{0:d}"HeaderText="Prescription Date"

HtmlEncode="False"SortExpression="prescription_date">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="home_phone"HeaderText="Patient Home Phone"SortExpression="home_phone">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="pharmacy_phone"HeaderText="Pharmacy Phone"SortExpression="pharmacy_phone">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="medication1"HeaderText="Medication"SortExpression="medication1">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="dosage1"HeaderText="Dosage"SortExpression="dosage1">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="frequency1"HeaderText="Frequency"SortExpression="frequency1">

<HeaderStyleHorizontalAlign="Left"Wrap="False"/>

</asp:BoundField>

<asp:BoundFieldDataField="refills"HeaderText="Number Of Refills"SortExpression="refills">

<HeaderStyleHorizontalAlign="Left"/>

</asp:BoundField>

<asp:BoundFieldDataField="amt_tablets"HeaderText="Number Of Tablets"SortExpression="amt_tablets">

<HeaderStyleHorizontalAlign="Left"/>

</asp:BoundField>

<asp:BoundFieldDataField="staff_comments"HeaderText="Staff Comments"SortExpression="staff_comments">

<HeaderStyleHorizontalAlign="Left"/>

</asp:BoundField>

</Columns>

<RowStyleBackColor="White"ForeColor="#003399"/>

<SelectedRowStyleBackColor="#009999"Font-Bold="True"ForeColor="#CCFF99"/>

<PagerStyleBackColor="#99CCCC"ForeColor="#003399"HorizontalAlign="Left"/>

<HeaderStyleBackColor="#003399"Font-Bold="True"ForeColor="#CCCCFF"/>

</asp:GridView>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>

protectedvoid CheckBox2_CheckedChanged(object sender,EventArgs e)

{

string cScript ="<script>alert('Another CheckBox already checked');</script>";

CheckBox chkCheckBox2 = (CheckBox)sender;

GridViewRow mySelectedRow = ((CheckBox)sender).Parent.ParentasGridViewRow;if(chkCheckBox2.Checked)

{

foreach (GridViewRow gvrin Prescgrid.Rows)

{

if(gvr!=mySelectedRow)

{

if(((CheckBox)gvr.FindControl("CheckBox2")).Checked)

{

ClientScript.RegisterStartupScript(typeof(Page),"clientscript",cScript);

chkCheckBox2.Checked =false;

}

}

}

}

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

string cScript ="<script>alert('First Select a Row');</script>";

bool blnFlag =false;

foreach (GridViewRow gvrin Prescgrid.Rows)

{

if (((CheckBox)gvr.FindControl("CheckBox2")).Checked)

{

//access all elements using myRow.FindControl blah blah

string strPatientID = ((Label)gvr.FindControl("Label1")).Text;blnFlag =true;

}

}

if (!blnFlag)

{

ClientScript.RegisterStartupScript(typeof(Page),"clientscript", cScript);

}

}

Regards,

Naveen

Labels: , , , , , , , , , , , , , , , ,

How to Handle Check box with Button Control

Hi All

I m having a gridview,button control on a form. In that PatientId is a templatefiled along with a check box.Per page i m going to display 10 records of a same patient.

My requirement is

1.user has to select only one check box if user selects more than one check box alert or message should be displayed.

2. If user checks only one checkbox i have to pick the particual row. I want to store all the values.

How to handle it.

I m able to get the values with checkbox, but i m unable with the button .

Here is my aspx page code

<asp:GridView ID="Prescgrid" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#3366CC" BorderStyle="None"
BorderWidth="1px" CellPadding="4" Height="49px">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Refill"
Text="Refill"></asp:LinkButton>

</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Patient_id" SortExpression="patient_id">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("patient_id") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("patient_id") %>'></asp:Label>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack=true OnCheckedChanged="Hai" />
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="prescription_date" DataFormatString="{0:d}" HeaderText="Prescription Date"
HtmlEncode="False" SortExpression="prescription_date">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="home_phone" HeaderText="Patient Home Phone" SortExpression="home_phone">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="pharmacy_phone" HeaderText="Pharmacy Phone" SortExpression="pharmacy_phone">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="medication1" HeaderText="Medication" SortExpression="medication1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="dosage1" HeaderText="Dosage" SortExpression="dosage1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="frequency1" HeaderText="Frequency" SortExpression="frequency1">
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="refills" HeaderText="Number Of Refills" SortExpression="refills">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="amt_tablets" HeaderText="Number Of Tablets" SortExpression="amt_tablets">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="staff_comments" HeaderText="Staff Comments" SortExpression="staff_comments">
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
</asp:GridView>
nbsp;

<asp:Button ID="Button1" runat="server" Text="Button" />

Waiting for valuable replies

Thank u

Baba

You may do better with a DataGrid if you are allowing multiple selections.

http://www.dotnetjohn.com/articles.aspx?articleid=83

Alternately, set up an array as a session variable and populate it with the DataKey for each row on the checkbox_checked event. You should be able to get that out of the event arguments. Then when you do whatever you do, iterate throught the array and pass those datakeys to the SQL statement or whatever you are using as a criteria class.


Hi Baba,

Try this.

http://forums.asp.net/t/1185169.aspx

Regards,

Naveen


Hisrijaya_ramaraju ,

srijaya_ramaraju@.yahoo.com:

1.user has to select only one check box if user selects more than one check box alert or message should be displayed.

You can use javascript to allow user to select only one check box.

srijaya_ramaraju@.yahoo.com:

2. If user checks only one checkbox i have to pick the particual row. I want to store all the values

You can use findcontrol method to get any controls in the row then retrieve it's value.

Have a look at this sample ,

1<div>2 <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">3 <Columns>4 <asp:TemplateField>5 <ItemTemplate>6 <asp:CheckBox ID="CheckBox1" runat="server" />7 </ItemTemplate>8 </asp:TemplateField>9 </Columns>10 </asp:GridView>1112 </div>13 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

1function check(self)2 {34 var items = document.getElementsByTagName('input');56for(var i =0;i7 {8if(items(i).type =='checkbox' && items(i).id != self.id && items(i).checked ==true)9 items(i).checked =false;10 }11121314 }

1protected void Page_Load(object sender, EventArgs e)2 {3if (!IsPostBack)4 {5 DataTable table =new DataTable();6 table.Columns.Add("age");7 table.Columns.Add("name");8 DataRow dr = table.NewRow();9 dr["age"] = 1;10 dr["name"] ="zz";11 table.Rows.Add(dr);1213 DataRow dr2 = table.NewRow();14 dr2["age"] = 2;15 dr2["name"] ="vv";16 table.Rows.Add(dr2);1718this.GridView1.DataSource = table;19 GridView1.DataBind();20 }212223//this.Button1.Attributes.Add("onclick","check(); return false;");24 }2526protected void Button1_Click(object sender, EventArgs e)27 {28for (int i = 0; i < GridView1.Rows.Count; i++)29 {30 CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");31if (chk.Checked ==true)32 {33string name = GridView1.Rows[i].Cells[2].Text;//get value here34 }35 }36 }3738protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)39 {40if (e.Row.RowType == DataControlRowType.DataRow)41 {42 CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");43 chk.Attributes.Add("onclick","check(this)");44 }45 }

Labels: , , , , , , , , , , , , ,