473,757 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

two (desperate) questions for ASP.NET and SQL Server 2005 Express

Hi there

I'm not sure that this is strictly relevant to the ASP.NET newsgroup, but
perhaps you've encountered a similar problem. Please help!!!

I'm using the "System.Data.Sq lClient" namespace in an ASP.NET application to
connect to a SQL Server 2005 Express database. Moreover, I'm using XCopy and
"Database=temp; AttachDBFilenam e='c:\temp\temp _Data.mdf'" in the connection
string when I attach to the database for the first time. (The database name
'temp' is used for purposes of this post only.) I encounter two problems:

(a) If I ever connect to the database a second time, I (understandably ) get
the following message from the ASP.NET compiler: Database
'c:\temp\temp_D ata.mdf' already exists. Could not attach file
'c:\temp\temp_D ata.mdf' as database 'temp'. It seems I need to be able to
detect, from VB.NET, whether the database has already been attached, and if
so, to use the customary connection string rather than AttachDBFilenam e. At
the moment, to work around this problem, I use "On Error GoTo ..."
statements so that, if the connection string containing "AttachDBFilena me"
results in an error, I try the normal connection method (database previously
attached), and if that returns an error, I show the user an error page.
Question: Is there a neater way to do this?

(b) Every week I use XCopy to attach another database containing updated
records. Again, I encounter the same error as above, but in this case I
can't use the On Error GoTo logic, for two reasons. Firstly, if I don't
delete the earlier version of the MDF file, the On Error GoTo logic simply
results in a connection established to the old database. Secondly, if I
delete the earlier version of the MDF file and attempt to attach the new MDF
file, I still get an error because, although a new .MDF file exists, a
database object named 'temp' already exists in SQL Express. It seems that I
need a method to delete the old database (both the MDF file and the database
within SQL Express) from VB.NET. Question: Am I right, or is there a neater
way to do this?

Any suggestions gratefully appreciated.

Best regards
Loane
Nov 19 '05 #1
1 1212
Never mind, sorted it out, this is a classic undocumented feature: The file
path and database name must be contained in ' '.

Dim strConn = "Data
Source=.\SQLEXP RESS;AttachDBFi leName='c:\temp \temp_Data.MDF' ;Database='temp ';Integrated
Security=SSPI;T imeout=60;Conne ction Timeout=60;"

Used in this way, neither questions (a) nor (b) in my post apply.

Best regards
Loane
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1178
by: bredal Jensen | last post by:
I'm currently downloading the Microsoft "Visual web developer 2005 Express" and i have a few questions in case someone could have insider informations about this. I have just attended a seminar with "Scott Guthrie" (Hope someone knows who this guy is) and i have been looking forward to get my hands on any widbey beta for web developement. So my questions are:
3
2539
by: Phil Lee | last post by:
Hi, I have a few questions regarding web services in .NET 2 1) Why, when I run code analysis do I get a source controlled files named {guid}/codeanalysislog.xml {guid}/webproject.lastcodeanalysissucceeded Can I stop this folder and it's files from being source controlled? It's a pain because after I've checked everything in FxCop fails until I check these files out.
1
6631
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an unexpected value. ***EndOfSession***? Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an...
3
1207
by: ljh | last post by:
(sorry if this posts twice....I waited several hours and didn;t see it - so here it is again.....) Perhaps I am somewhat dense.....but, I still need to know..... What do you need to do in order to ship a SQL server Express or Developer edition database with your Visual Studio .Net 2005 application? Does SQL Server Express need to be installed on the target machines? Or, can the database file be used as a stand-along databse (like an...
10
2112
by: amjad | last post by:
how to connection sql server table with aspx like pulling data from table to grid view.... simple example to start .... thanks
0
1106
by: Jeff | last post by:
Hey I have 2 questions about visual web developer 2005 express edition: 1) As far as I know visual web developer 2005 express edition has a built in limitaion to only local databases, but can a vwd project be opened in a full version of visual studio 2005 and rebuilt? and after being rebuilt configure it to access db on another server? is that possible?
24
1536
by: Jimmy | last post by:
hi everyone. building a website for a client and have a few questions related to best practices, what i should use etc... the site will use a database to store info entered by users. each visit will allow the user to input no more than 2 fields: email address, and a comment field. the site has the potential to become pretty busy so my first question is, what should i use on the backend? a dedicated SQL server isnt an option so im looking...
3
2621
by: leonaisse | last post by:
Hi I have a bunch on tables and data in my local SQL Server 2005 Express master DB and I want to export it to a database.mdf within my wwwroot (visual studio) file - how can i do this? Thanks for you help leonaisse
3
6442
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I get an error at the end of the SQL server install phase 'Invalid endpoint'. (Note SQL server express gets installed OK) If I run SQL server express SP2 setup directly it I don't get the error
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.