Wrox Programmer Forums
|
BOOK: Beginning C# 2005 Databases
This is the forum to discuss the Wrox book Beginning C# 2005 Databases by Karli Watson; ISBN: 9780470044063
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 2005 Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 30th, 2007, 10:17 AM
Authorized User
 
Join Date: Aug 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO.NET error

I'm sure there's probably something dumb that I,ve done or overlooked but following Chapter 6 Try it Out example, when run the application I keep getting the following message

Enter table to count records for:
Character
An attempt to attach an auto-named database for file C:\Visual C# 2005 Databases
\Chapter06 Ex0601 - Executing Comm
ands\FolktaleDB.mdf failed. A database with the same name exists, or specified f
ile cannot be opened, or it is located on UNC share.
There are -1 rows in the table [Character].
Press ENTER to close.

has anyone got any ideas ? as this is very frustrating

 
Old May 7th, 2007, 08:47 AM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The trick here is to know that there are two ways to deal with database connections. The first is to attach the database at the time of connection which is useful if you want to work with multiple versions. The second is to attach a single database permanently and refer to it by name in the connection. However, these techniques are not compatible. What the connection is complaining about when it says 'A database with the same name exists' is that the database named FolktaleDB.mdf is already attached to the server. So you need to use Management Studio to detach this database so you can attach it at connection time. I prefer to use a single database permanently attached to the server which requires a different connection string.
This connection works for me:
<connectionStrings>
    <add name="FolktaleDBConnectionString"
      connectionString="Data Source=.\SQLEXPRESS;
      Database=FolktaleDB;
      Integrated Security=True"/>
  </connectionStrings>
 
Old May 9th, 2007, 03:10 AM
Authorized User
 
Join Date: Aug 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that....kinda got confused over this issue,learning from ASP.NET I found that I like to place the DB in the application directory and use a standard format connection string :-
<add name="MyConnectionString"
             connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\Test.mdf;Integrated Security=True;User Instance=True"/>
as apposed to path directory names of C:/dir/dir or issues when connecting to db's on the server, this works fine for me and ensures that I don't get tripped up again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
Ado.Net Error digby_dog VB.NET 2002/2003 Basics 2 June 7th, 2005 04:29 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
Beginning ASP.NET E-Commerce (ADO error) dianastudy3 All Other Wrox Books 3 July 30th, 2003 11:51 PM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.