An attempt to attach an auto-named database for file

0

I am working on a login in ASP but when I do the query it sends me the following error:

  

An attempt to attach an auto-named database for file C: \ Users \ Jose Pablo \ Documents \ Visual Studio 2015 \ WebSites \ ProyectoFinal \ App_Data \ shopping.mdf failed. A database with the same name exists, or specified file can not be opened, or it is located on UNC share.

Source code error:

  

Line 20: protected void b1_Click (object sender, EventArgs e)

     

Line 21: {

     

Line 22: with.Open ();

     

Line 23: SqlCommand cmd = con.CreateCommand ();

     

Line 24: cmd.CommandType = CommandType.Text;

This is my código :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class admin_adminlogin : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C: \Users\Jose Pablo\Documents\Visual Studio 2015\WebSites\ProyectoFinal\App_Data\shopping.mdf;Integrated Security=True");
int i = 0;
protected void Page_Load(object sender, EventArgs e)
{

}

protected void b1_Click(object sender, EventArgs e)
{
    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "select * from admin_login where username '"+t1.Text+"' and password '"+t2.Text+"' ";
    cmd.ExecuteNonQuery();
    DataTable dt = new DataTable();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    i = Convert.ToInt32(dt.Rows.Count.ToString());
    Response.Write(i);
    con.Close();

}
}
    
asked by José Pablo Santizo 17.11.2017 в 22:45
source

0 answers