Monday, July 27, 2009

ASP.NET 2.0 c# program is not connect to sql server 2005?

This is the program





protected void Button1_Click(object sender, EventArgs e)


{





string isuruConnectionString = "Data source=HOME-D476A40965/SQLEXPRESS;Initia... Catalog=isuru; Integrated Security=True";








string sql = "INSERT INTO tan(name,passwd)value('333','444')";


SqlConnection con = new SqlConnection(isuruConnectionString);


con.Open();


SqlCommand cmd = new SqlCommand(sql, con);








con.Open() line is highlighted and display this error.





An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)





But I was alow remote connection to sql server using "sql server serface aria configuration"option.And I using visual studio 2005.





What is the problem(s)?.

ASP.NET 2.0 c# program is not connect to sql server 2005?
The first question should be whether you are connecting to SQL Server on a remote machine or on the same machine.





If on the same machine,


Then you should configure the connection to be "Shared Memory" - Then everything will "just work" unless you have a typo somewhere.





If you configure Named Pipes or TCP/IP, then you likely will need to make sure your security is right.





Connecting to a database on another machine is a bit more complex because you %26lt;must%26gt; connect using a remote connection. Your sql connection string specifies it's using Integrated Security. The only way that can really work is if both machines are part of the same Domain and the security context of your connection string is a Domain User account.





Lastly, I'm not sure what you are really trying to do... It looks like you're inserting a username/password credential pair into a table? It's possible but a somewhat odd thing to do if your application uses integrated security... The purpose of something like this just wouldn't be for the application itself generally.


No comments:

Post a Comment