was using c# to develop some application and wanted to connect my application(windows) with SQL database.
using sql 2005 express and visual c# express;
but it kept on throughing the following exception while i try to run my app.
so help me out
"An attempt to attach an auto-named database for file C:\Program Files Microsoft SQL Server MSSQL.1MSSQL Data mann.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

Could you send code you are using?

Could you send code you are using?

here u are !

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        SqlConnection SqlConn;
        SqlDataAdapter dat;
        DataSet set;



        private void Form1_Load(object sender, EventArgs e)
        {

            }

        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Program Files Microsoft SQL Server MSSQL.1 MSSQL Data adila.mdf ;Integrated Security=True;Connect Timeout=30;User Instance=True";
            string updatrec = "INSERT INTO one(name,fathers) VALUES   (@name, @fathers)";
            SqlConn = new SqlConnection();
            SqlConn.ConnectionString = constring;

            SqlCommand sqlCmd = new SqlCommand(updatrec, SqlConn);

            sqlCmd.Parameters.AddWithValue("@name", textBox1.Text);
            sqlCmd.Parameters.AddWithValue("fathers", textBox2.Text);



            try
            {
                SqlConn.Open();
                sqlCmd.ExecuteNonQuery();
            }
            catch (System.Exception Exec)
            {
                MessageBox.Show(Exec.Message);
            }

            SqlConn.Close();

        } 
        }
    }

Make sure the user account you are using is configured in SQL

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.