Attach SQL DB to SQL Server 2005 using VB.Net

Is there any way to attach a SQL DB to SQL Server 2005 using VB.Net?  If so can you also set security?

0
jharwood
10/12/2007 4:56:00 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies
1663 Views

Similar Articles

[PageSpeed] 42

Can you rephrase your question? Attach SQL DB from which version of SQL server ? Look up books online for sp_attachdb and sp_detachdb.


***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
10/12/2007 6:36:31 PM

I have a DB that was created in SQL Server 2005.  I have a website that displays data from systems all over the world.  Each system sends it's data to it's own DB.  The customer can then go to a website and see the data at real time.  What I am trying to do is automate the process for new systems.  Each system has it's own portion of the website and its own DB.  When an employee enters information into a form on the website it creates the new portion of the site and inserts a new DB into SQL Server 2005.  I have everything working except for inserting the DB into SQL Server 2005.

0
jharwood
10/15/2007 12:38:14 PM

I figured it out thanks for pointing me in the right direction with the sp_attach_db.  The accual code is:

Dim objConn As New SqlConnection("Server=Web-Testbed;uid=CreateDBs;pwd=ABC123;database=master")

objConn.Open()

Dim objCmd As New SqlCommand("EXEC sp_attach_db @dbname = N'" & DBname & "', @filename1 = N'X:\sites\" & DBname & "\Database\" & DBname & ".mdf', @filename2 = N'X:\sites\" & DBname & "\Database\" & DBname & "_log.ldf'", objConn)

objCmd.CommandType = CommandType.Text

objCmd.ExecuteNonQuery()

objConn.Close()

 

0
jharwood
10/15/2007 2:04:25 PM
Reply:

Similar Artilces:

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers
When I connect SQL Server 2005 to a remote database i get the error: "This version of Microsoft Sql Server Management Studio can only be used to connect to Sql Server 2000 and Sql Server 2005 servers". Can I confirm it is because: the remote db is of SQL Server 2008? There is a soln mentioned in http://forums.asp.net/t/1324047.aspx Did anybody try this (installing 2008 express: http://www.microsoft.com/express/sql/download/)? I am just checking again, whether it will disturb my existing SQL Server installation, in any means...? Though it is mentioned that it will g...

I cannot stop Visual Studio.NET 2005 from looking for SQL Server 2005 instead of SQL 2000
I would like to know how to set SQL2000 as the default database server when running any webapplication. I have installed Visual Studio.NET and SQL Server 2000 locally in my laptop.  But anytime I want to run a webapplication I am getting the following error:System.Data.SqlClient.SqlException was unhandled by user code  Class=20  ErrorCode=-2146232060  LineNumber=0  Message="An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server doe...

Using VB.NET to export data from SQL Server 2005 to Excel
Hi There, I just want to know how to export data from SQL Server 2005 to an excel spread sheet, using VB.NET?ThanksSJB  Everytime I should export data from SQL to Excel with code, I simply create a ; seperated file (*.csv). So if you want to do the same you can simply use ADO.Net to query your database and get a result set from your tables. Walk trough the rows and get its value and create a textfile with the System.IO namespace. The file can look like: column1;column2;column3 value1;value2;value3 value1;value2;value3 The first row can if you want have the name of the column tha...

How do I synchronise local SQL Server Express db with my online SQL Server 2005 db?
For various reasons, I have a situation where the data in the SQL Server 2005 database hosted by my ISP is more up to date than the data in the matching SQL Server Express database on my own PC. I now want to synchronise these two databases but don't know how to do it. Because I am still developing my ASP.NET 3.5 app, which has not yet been opened up to users, I am only used to synchronising in the other direction by first using the Database Publishing Wizard within Visual Web Developer 2008 Express to create a suitable script associated with my SQL Server Express database and then runn...

Sql Server Script File(.sql) Execution by Vb.net Code
I have a problem. I m working on "light weight sql server"  project.   and i want to execute .sql file through vb.net code with the help of sqldmo library and sqlns namespace. but i donot know any method to directly execute the .sql file. i am successfully making the full script of select database of sql server.   please help me.... thanks.... Hi, You can use SQL-DMO object in your .net projects by referencing Sqldmo.dll  file which is in  C:\Program Files\Microsoft SQL Server\80\Tools\Binn  folder is default installation parameters are used. I...

SQL Server 2005 Installation problems with SQL Server Express & SQL Server 2000
Hi Guys, I have had SQL Server Express and Sql Server Management Studio Express installed on my machine for some time and recently tried to install a trial of SQL Server 2005 as well.  (Yes, I'm migrating from Visual Studio Express to Visual Studio Professional, just as in tended!) Everything went fine except that nothing seemed to be installed.  I searched in all the obvious places - both on the Start/Programs menu and on the hard-drive: nothing. A check under Add/Remove Programs showed that Sql Server 2005 Express was installed, but called SQL Server 2005. So after a number o...

VB.NET Codebehind Code to Update SQL Server 2005 Using SQLDataSource Control?
Hi, I am a newbie in using ASP.NET 2.0 and ADO.NET.  I wrote a hangman game and want to record statistics at the end of each game.  I will create and update records in the database for each authenticated user as well as a record for the Anonymous, unauthenticated user.  After a win or loss has occurred, I want to programmatically use the SQLDataSource control to increment the statistics counters for the appropriate record in the database (note I don't want to show anything or get user input for this function). I need a VB.NET codebehind example that will show me how I sho...

shopping cart in VB.NET, uses SQL server express edition 2005, anyone?
Hello i want to create a shopping cart which uses SQL server express 2005 as the database for my school project...Any good tutorials for this? Perhaps you can delve in to the source code of some of the open source offerings out there? Maybe DotShoppingCart or dashCommerce, both of which you can find links to on the Starter Kits and Community Projects page.Gavin HarrissPortfolio: www.gavinharriss.com Thank you very much for the suggestion! :)  my friend gave me a great shopping cart code which uses VB.net and SQL server express edition! Once again, thanks :)  ...

uploading a image in to the sql server 2005 database using vb.net 3.5
i am currently developing a web project using asp.net.i need to upload a image file to the database using asp.net.i am using linq to interactwith the database. can some one help me in writing these codes. {i need to know how to get the image size and i need the image content type to upload image) please let me know what are the codes i should use to get the image size and content type. i have used the following code but no use                           &n...

creating ssis packagte for sql server to sql serer using C#.net
Hi friendsdoes any one has code or urls which can help me to create the ssis pacakage which will transfer data from sql server to sql server databaseswith some manipulationsthanks so much Lad LaxmikantPune You are probably in the wrong forum.  This forum is for questions relating to ASP.NET Dynamic Data. thanks,David...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi (and HELP!),   I downloaded the Personal WebSite Starter Kit and got it working no problem on my local machine.  But I've had nothing but frustration trying to get it up and running on a webhosting site.  I picked hostmysite.com which uses SQL Server 2005.  I was under the impression that it wouldn't be that big a deal to convert the .MDF files that Sql Server Express uses to a SQL Server 2005 database.  I tried using SQL Server Management Studio Express.  I was able to "see" my remote database on hostmysite.com, but I was not able to import the .mdf file...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi (and HELP!),   I downloaded the Personal WebSite Starter Kit and got it working no problem on my local machine.  But I've had nothing but frustration trying to get it up and running on a webhosting site.  I picked hostmysite.com which uses SQL Server 2005.  I was under the impression that it wouldn't be that big a deal to convert the .MDF files that Sql Server Express uses to a SQL Server 2005 database.  I tried using SQL Server Management Studio Express.  I was able to "see" my remote database on hostmysite.com, but I was not able to import the .mdf files ...

Converting MDF files (SQL Server Express) to SQL Server 2005 WITHOUT having to buy SQL Server 2005 (I have Express). Personal WebSite Starter Kit
Hi,Basically i built a webpage with Login and it's working well from my local machine.Right now, i'm using Database Publishing Wizard. the problem is how do i convert.MDF files to .SQL 2005 to get my database publish in the internet? thanks  Place your .MDF file in the App_Data directory, change the connection string accordingly and then publish your web site. ----------------------------------------------------------Please click Mark As Answer if this helped in solving your problem.  Please click "Mark As Answer" if this hepled in solving your problem. ...