Reputation: 56
The compiler is giving me this error:
An attempt to attach an auto-named database for file failed. A database with the same name exists or specified file cannot be open, or it is located on UNC share.
I've been reading around other stackoverflow posts and they mention it might be a connectionstring problem, but I'm coding this in linq, not ado.net code. I don't use a traditional connectionstring. In fact, I had to use a namespace to call the tableAdapter in order for me to access the data source I needed.
The code being used is as follows:
using CustomerInvoices.MMABooksDataSetTableAdapters;
namespace CustomerInvoices
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
MMABooksDataSet mmaBooksDataSet = new MMABooksDataSet();
InvoicesTableAdapter invoicesTableAdapter = new InvoicesTableAdapter();
CustomersTableAdapter customersTableAdapter =
new CustomersTableAdapter();
private void Form1_Load(object sender, EventArgs e)
{
invoicesTableAdapter.Fill(mmaBooksDataSet.Invoices);
customersTableAdapter.Fill(mmaBooksDataSet.Customers);
var invoices = from invoice in mmaBooksDataSet.Invoices
join customer in mmaBooksDataSet.Customers
on invoice.CustomerID equals customer.CustomerID
orderby customer.Name, invoice.InvoiceTotal descending
select new
{
customer.Name,
invoice.InvoiceID,
invoice.InvoiceDate,
invoice.InvoiceTotal
};
string customerName = "";
int i = 0;
foreach (var invoice in invoices)
{
if (invoice.Name != customerName)
{
lvInvoices.Items.Add(invoice.Name);
customerName = invoice.Name;
}
else
{
lvInvoices.Items.Add("");
}
lvInvoices.Items[i].SubItems.Add(invoice.InvoiceTotal.ToString());
lvInvoices.Items[i].SubItems.Add(Convert.ToDateTime
(invoice.InvoiceDate).ToShortDateString());
lvInvoices.Items[i].SubItems.Add
(invoice.InvoiceTotal.ToString("c"));
i += 1;
}
}
}
}
Upvotes: 0
Views: 74
Reputation: 56
I figured it out. Thru the data source, I went into the connection property window and found the connection path file, I changed it to the correct one
Data Source=localhost\sqlexpress;Initial Catalog=MMABooks;Integrated Security=True
And it Worked. It seems the error is because the connectionString was pointing to the wrong path file. Hope this helps others. Thank you.
Upvotes: 1