Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2013 05:47 AM by kaysar98
0 Points
2 Posts
Jan 27, 2013 02:30 PM|LINK
Hi Experts,
I have develop a sample web application with gridview and sql server as db.
But i have an error in con.open() -- Instance Failure
web.config
<connectionStrings> <add name ="vel" connectionString="server=MURUGAVEL-PC\\SQLEXPRESS; database=Northwind; Integrated Security=True" /> </connectionStrings>
Test.cs
SqlConnection con = new SqlConnection(); SqlCommand cmd = new SqlCommand(); SqlDataReader dr; con.ConnectionString = ConfigurationManager.ConnectionStrings["vel"].ConnectionString; con.Open(); cmd.CommandText = "select * from Employees"; cmd.CommandType = CommandType.Text; cmd.Connection = con;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr; GridView1.DataBind();
con.Close();
Plz help me out
Thanks Murugavel S
Participant
766 Points
161 Posts
Jan 28, 2013 03:32 AM|LINK
Try This,
Data Source=.\\SQLEXPRESS;" - It's the double \\. That's an escape sequence in C#. Switch the connection string to .\SQLEXPRESS.
Contributor
3014 Points
575 Posts
Jan 28, 2013 03:54 AM|LINK
Try this :
con.ConnectionString = ConfigurationManager.ConnectionStrings["vel"].ToString;
Lets give it a try and let us know.
1115 Points
264 Posts
Jan 28, 2013 04:22 AM|LINK
use dbconnectionstring , and get more readable error. then it easy to find and resolve the bug :)
System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder(); builder["Data Source"] = "(local)"; builder["integrated Security"] = true; builder["Initial Catalog"] = "AdventureWorks;NewValue=Bad";
SqlConnection sqlConnect = new SqlConnection(builder.ConnectionString); Console.WriteLine(sqlConnect.ConnectionString);
sqlConnect.open();
Member
178 Points
39 Posts
Jan 28, 2013 05:47 AM|LINK
try with this:
con.ConnectionString = ConfigurationManager.ConnectionStrings["vel"].ToString();
murugaveltrp
0 Points
2 Posts
Gridview
Jan 27, 2013 02:30 PM|LINK
Hi Experts,
I have develop a sample web application with gridview and sql server as db.
But i have an error in
con.open() -- Instance Failure
web.config
<connectionStrings>
<add name ="vel" connectionString="server=MURUGAVEL-PC\\SQLEXPRESS; database=Northwind; Integrated Security=True" />
</connectionStrings>
Test.cs
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
con.ConnectionString = ConfigurationManager.ConnectionStrings["vel"].ConnectionString;
con.Open();
cmd.CommandText = "select * from Employees";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
Plz help me out
Thanks
Murugavel S
Milind986
Participant
766 Points
161 Posts
Re: Gridview
Jan 28, 2013 03:32 AM|LINK
Try This,
Data Source=.\\SQLEXPRESS;" - It's the double \\. That's an escape sequence in C#. Switch the connection string to .\SQLEXPRESS.
My Blog
Sujeet Saste
Contributor
3014 Points
575 Posts
Re: Gridview
Jan 28, 2013 03:54 AM|LINK
Try this :
Lets give it a try and let us know.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
arunoyour
Participant
1115 Points
264 Posts
Re: Gridview
Jan 28, 2013 04:22 AM|LINK
use dbconnectionstring , and get more readable error. then it easy to find and resolve the bug :)
SqlConnection sqlConnect = new SqlConnection(builder.ConnectionString); Console.WriteLine(sqlConnect.ConnectionString);Visit :: www.simplyasp.blogspot.com
Stay tune...Keep alive
kaysar98
Member
178 Points
39 Posts
Re: Gridview
Jan 28, 2013 05:47 AM|LINK
try with this: