Hello!
Just a little bug but can make a funny crash (this is all the code)
After to write my codes when "ctrl+f5" its crash and showing me this error message from the .aspx.:
The connection name 'Mfwamba' was not found in the application configuration or the connection string is empty
But the real name of my dbconnection is really 'Mfwamba'. Why this message then? Thanx.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowDetails.aspx.cs" Inherits="ShowDetails" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
////////////////////////////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ShowDetails : System.Web.UI.Page
{
string strcon = "Data Source=localhost\\sqlexpress;Integrated Security=true;Initial Catalog=Mfwamba";
SqlConnection con;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
con = new SqlConnection(strcon);
con.Open();
cmd = new SqlCommand("Select * from Emp where Empid=@id", con);
cmd.Parameters.AddWithValue("@id", DropDownList1.Text);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
Label1.Text = dr[1].ToString();
Label2.Text = dr[2].ToString();
Image1.ImageUrl = "~/Handler.ashx?id=" + DropDownList1.Text;
}
con.Close();
}
}
Sanjeeb LenkaPosted Jul 23, 2013, 10:59 AM
just check your web.config. may be you forgot to write the connection string in web.config.
ex:
write you connection string and check:
localhost: your server name
myDb: your database name
myUser: your sql userid
myPass: your password
Riyaz AkhtarPosted Jul 23, 2013, 8:58 AM