Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i find the below error in my mvc project, i get error in open connection line
System.ComponentModel.Win32Exception: The system cannot find the file specified


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using Vipadm.ViewModals;
namespace Vipadm.Models
{
    public class DBConn
    {
        //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-PNV2C7S; Database=RI400;integrated security=true");
        SqlConnection con = new SqlConnection("Data Source=DESKTOP-PNV2C7S\SQLEXPRESS;Initial Catalog=RI400;User ID=sa;Password=gajula");
        public void Clientdata(Client cl)
        {
            SqlCommand cmd = new SqlCommand("insert into clients(ClientName,VATNumber,Address1) values(@ClientName,@VATNumber,@Address1)", con);
            cmd.Parameters.AddWithValue("@ClientName",cl.ClientName);
            cmd.Parameters.AddWithValue("@VATNumber", cl.VATNumber);
            cmd.Parameters.AddWithValue("@Address1", cl.Address1);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
}
Posted
Comments
ZurdoDev 4-Jan-18 7:21am    
con.Open() is the line that causes that error?
Richard MacCutchan 4-Jan-18 7:24am    
The system cannot find the file. This message could not be clearer.
F-ES Sitecore 4-Jan-18 7:49am    
Use SQL Management Studio to see if you can connect to DESKTOP-PNV2C7S\SQLEXPRESS, the database might not be configured properly.

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