Click here to Skip to main content
15,921,279 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am just checking database connection in my system... But i got the error like this...
Error:System.ComponentModel.Win32Exception: The system cannot find the file specified

My Code is..
DEFAULT.ASPX:

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

DEFAULT.ASPX.CS:
C#
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;


protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = "Data Source=User-PC;Initial Catalog=master;uid=sa;pwd=picme123; Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
Response.Write("Connected");
conn.Close();
}

Pls any one help me.. I think i have a problem in my webconfig... how to rectify this..
Posted

1 solution

Put try catch

and in try catch you should put following code
C#
if(conn.Connection != ConnectionState.Closed)
{

conn.Connection.Close();
conn.Dispose();
}
 
Share this answer
 
v2
Comments
Member 10463904 24-Jul-14 7:46am    
pls send full cod for db connection using try catch method

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900