the source code of the page is as below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="executiveinfo.aspx.cs" Inherits="executiveinfo" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
and the C# code is:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class executiveinfo : System.Web.UI.Page
{
SqlConnection cnn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LMS;Data Source=SHESH-PC\SHESHSQLEXPRESSS");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cm = new SqlCommand();
string sql = "insert into executiveinfo(executivename,branchcode,address,city,emailid,gender,mobileno,remark,entrydate)values('" + txtexecutivename.Text + "','" + ddlbranchcode.SelectedItem.ToString() + "','" + txtaddress.Text + "','" + ddlcity.SelectedItem.ToString() + "','"+txtemailid.Text+"','" +RadioButtonList1.SelectedItem.ToString() + "'," + txtmobileno.Text + ",'" + txtremark.Text + "','" + DateTime.Now.ToString() + "')";
cm.Connection = cnn;
cm.CommandType = CommandType.Text;
cm.CommandText = sql;
int a = 0;
cnn.Open();
a = cm.ExecuteNonQuery();
cnn.Close();
if (a == 0)
{
lblmsg.Text = "DATA NOT SAVED";
}
else
{
lblmsg.Text = "DATA SAVED";
}
}
}
and the error is at line 48 col 1 in the code line{cnn.Open();} and the table is dbo.executiveinfo
and schema of table is:
Column_name Type Computed Length Prec Scale
id numeric no 9 18 0
executivename varchar no 50
branchcode varchar no 30
address varchar no 50
city varchar no 50
emailid varchar no 50
gender varchar no 50
mobileno numeric no 9 18 0
remark varchar no 50
entrydate datetime no 8
activestatus bit no 1
Kunal VaishyaPosted Apr 27, 2012, 12:54 AM
Connection String
Data Source=SHESH-PC\SHESHSQLEXPRESSS;Initial Catalog=LMS;Integrated Security=True
if still get error then let me know if you are using user name and passwordalso mention
Shesh MishraPosted Apr 27, 2012, 12:17 AM
SqlException was unhandled by user code
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Bryian TanPosted Apr 27, 2012, 12:08 AM
What exactly is the error?
Shesh MishraPosted Apr 26, 2012, 11:56 PM
Maziyar NazaryanPosted Apr 26, 2012, 10:36 PM
And I will be OK?
Open SQL
than expand security - > Login
and creaye new login
username : SHESH-PC/ASPNET
and than in grant access tab your database select