<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx</link><description>I've been getting asked a lot lately about how to easily attach a local SQL Server/Express database file (.MDF file) to an instance of SQL Server (any edition) . In most of my samples I distribute local SQL Server databases and use user instance connection</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Attaching a Local SQL Express Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9239237</link><pubDate>Fri, 19 Dec 2008 03:55:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9239237</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;Beth,&lt;/p&gt;
&lt;p&gt;Please why not use sql server?&lt;/p&gt;</description></item><item><title>Attaching a Local SQL Express Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9239268</link><pubDate>Fri, 19 Dec 2008 04:00:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9239268</guid><dc:creator>No1 Microsoft Fan</dc:creator><description>&lt;p&gt;More goodness from Beth Massi: I've been getting asked a lot lately about how to easily attach a local&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Express Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9239370</link><pubDate>Fri, 19 Dec 2008 04:18:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9239370</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Tony,&lt;/p&gt;
&lt;p&gt;What do you mean exactly? MDF files are SQL Server database files. If you are referring to using SQLCmd instead of SSMS then it's because SQLCmd is easier when you don't have the log file (LDF) available. &lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Express Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9241859</link><pubDate>Fri, 19 Dec 2008 15:04:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9241859</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;Beth I mean sql express, in the real working (telecommunications) is not installed in my company. &amp;nbsp;Only sql server is installed on our dev servers. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think you should target more real world examples.&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242222</link><pubDate>Fri, 19 Dec 2008 18:07:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242222</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Tony,&lt;/p&gt;
&lt;p&gt;Umm... that's what this post is all about. SQL Express and SQL Server work the same way when you want to attach database files. SQL Express allows you to have user connections and work with local database files. This post shows you how to take all the samples where I distribute the databases, and instead attach them to your instances -- whether that is sqlexpress or server (I mention &amp;quot;developer edition or higher&amp;quot; in the second paragraph). Sorry I wasn't clear, I updated the wording in the post. &lt;/p&gt;
&lt;p&gt;And SQL Express is very real world. It's a great FREE database for small-medium businesses. And upgrading is just a matter of attaching the database to SQL Server like I showed above.&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242390</link><pubDate>Fri, 19 Dec 2008 19:42:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242390</guid><dc:creator>monkey</dc:creator><description>&lt;p&gt;I only find it necessary to move my express db files on Windows Millenium Edition 2008 (aka Vista), otherwise I only use express in website development and attach them in place.&lt;/p&gt;
&lt;p&gt;The security and deployment defects of Vista are my #1 complaint about this half baked wad of recursive dough eating dough.&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242446</link><pubDate>Fri, 19 Dec 2008 20:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242446</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Monkey,&lt;/p&gt;
&lt;p&gt;I'm running as admin on Vista and user instances connect just fine. If you're doing web development then there are some issues when the ASPNET user is auto-attaching to the user instance. If ASPNET does not have write permissions on the database files, the connection fails. (Also see this post for a specific Vista issue with an easy fix: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/joestagner/archive/2008/03/12/sql-express-failed-generate-a-user-instance.aspx"&gt;http://blogs.msdn.com/joestagner/archive/2008/03/12/sql-express-failed-generate-a-user-instance.aspx&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;However I think attached databases are easier to work with when developing. For attached databases I wrote about how to enable remote connections on Vista here: &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/bethmassi/archive/2008/09/17/enabling-remote-sql-express-2008-network-connections-on-vista.aspx"&gt;http://blogs.msdn.com/bethmassi/archive/2008/09/17/enabling-remote-sql-express-2008-network-connections-on-vista.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do find Vista to be a little more pesky when developing on it because of it's security model but in general it's been fine with respect to using Visual Studio 2008 and SQL Express. &lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242643</link><pubDate>Fri, 19 Dec 2008 21:45:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242643</guid><dc:creator>monkey</dc:creator><description>&lt;p&gt;My gripe about Windows Millenium Edition 2008: The Sequel has to do with the deployment of application databases and the broken linkage mechanism. This isn't a problem for Cassini website development, but if you try to deploy a windows solution that uses 32 &amp;amp; 64 bit versions of SQL Express, Vista will fail to locate &amp;amp; link your database properly.&lt;/p&gt;
&lt;p&gt;It is better the be the balmer than the balmy, apparently the most when they are handing out pay; hence the world economy blue screen.&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242655</link><pubDate>Fri, 19 Dec 2008 21:58:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242655</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Thanks for the feedback Monkey. Though I'm not sure what problem you're running into so it's hard for me to suggest a solution. It sounds like IIS security related to the ASPNET user in which there is a weird fix that requires you to delete the SQLEXPRESS temporary directory. &lt;/p&gt;
&lt;p&gt;Do you have a link handy that explains the issue?&lt;/p&gt;
&lt;p&gt;TIA,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9242730</link><pubDate>Fri, 19 Dec 2008 22:43:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9242730</guid><dc:creator>monkay</dc:creator><description>&lt;p&gt;Do you know how to change the database name setting in the mdf? Case: copying &amp;amp; renaming a database file to be attached with a new name. This was not previously a problem, either there was no signature or the attach event updated the reference, but now it throws an error.&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9448681</link><pubDate>Fri, 27 Feb 2009 15:49:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9448681</guid><dc:creator>Walter</dc:creator><description>&lt;p&gt;Hi Beth - love the videos.&lt;/p&gt;
&lt;p&gt;I'm trying to attach the OMS database and I get the error:&lt;/p&gt;
&lt;p&gt;&amp;quot;File activation failure. The physical file name &amp;quot;C:\Users\bethma\Documents\Visual Studio 2005\Projects\FormsOverData\OrderManager2\OrderManager\OMS_log.ldf&amp;quot; may be incorrect.&lt;/p&gt;
&lt;p&gt;The log cannot be rebuilt when the primary file is read-only.&lt;/p&gt;
&lt;p&gt;Msg 1813, Level 16m State 2, Server...&lt;/p&gt;
&lt;p&gt;Could not open new database 'BethMassi1OMS'. Create Database is aborted.&amp;quot;&lt;/p&gt;
&lt;p&gt;I checked the MDF file and it is not read only.&lt;/p&gt;
&lt;p&gt;Can you help me with this?&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9448844</link><pubDate>Fri, 27 Feb 2009 17:29:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9448844</guid><dc:creator>ahmad@isoftwarehouse.net</dc:creator><description>&lt;p&gt;hallo ....&lt;/p&gt;
&lt;p&gt;how add automatic attach database, to sqlexpress in setupdeployment in vb.net&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9449263</link><pubDate>Fri, 27 Feb 2009 20:48:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9449263</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Walter,&lt;/p&gt;
&lt;p&gt;You'll need to make sure the name of the dataabse is OMS.mdf for those samples when you attach it using sqlcmd. &lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9470879</link><pubDate>Wed, 11 Mar 2009 22:00:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9470879</guid><dc:creator>Bill</dc:creator><description>&lt;p&gt;Thanks Beth.&lt;/p&gt;
&lt;p&gt;Just what I needed.&lt;/p&gt;
&lt;p&gt;Bill&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9536651</link><pubDate>Tue, 07 Apr 2009 23:59:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9536651</guid><dc:creator>Abraham zilva</dc:creator><description>&lt;p&gt;how can i attach a file.mdf file from sqlexpress back to visual studio2008. (i attached file.mdf to sql express from visual studio to add the schemas needed for user rolls, but now i can't get it back to visual studio)&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9580739</link><pubDate>Thu, 30 Apr 2009 19:53:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9580739</guid><dc:creator>Haroon Shaikh</dc:creator><description>&lt;p&gt;can you please tell me the attaching and detaching of mdf files by sqlcmd in sqlexpress using a batch files&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9647068</link><pubDate>Thu, 28 May 2009 15:45:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9647068</guid><dc:creator>Paul</dc:creator><description>&lt;p&gt;Beth,&lt;/p&gt;
&lt;p&gt;I got this after doing the last &amp;quot;GO&amp;quot;&lt;/p&gt;
&lt;p&gt;Msg 948, Level 20, State 1, Server BUG-FUJITSU\SQLEXPRESS, Line 1&lt;/p&gt;
&lt;p&gt;The database 'OMS' cannot be opened because it is version 655. This server suppo&lt;/p&gt;
&lt;p&gt;rts version 612 and earlier. A downgrade path is not supported.&lt;/p&gt;
&lt;p&gt;Msg 1813, Level 16, State 2, Server BUG-FUJITSU\SQLEXPRESS, Line 1&lt;/p&gt;
&lt;p&gt;Could not open new database 'OMS'. CREATE DATABASE is aborted.&lt;/p&gt;
&lt;p&gt;Please help.&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9685679</link><pubDate>Tue, 02 Jun 2009 18:27:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9685679</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Paul,&lt;/p&gt;
&lt;p&gt;This message means you are trying to attach a SQL 2008 database to a SQL 2005 instance. The version of the OMS database you have must be the 2008 version. You can install SQL 2008 Express for free or you can download the 2005 version of the OMS database from this 2005 sample here: &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=vbvideosdata&amp;amp;DownloadId=69"&gt;http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=vbvideosdata&amp;amp;DownloadId=69&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9914820</link><pubDate>Thu, 29 Oct 2009 17:08:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9914820</guid><dc:creator>Pedro</dc:creator><description>&lt;p&gt;Hello Beth, first of all let me congrat you on your videos... are making my learning a lot less painful...&lt;/p&gt;
&lt;p&gt;Now my question is...&lt;/p&gt;
&lt;p&gt;I made a SQL database connection on my application... Now I want to deploy it and make it a multi-user dababase... I want to have jsut one instance of the database where all people connect... How can I configure the connection string to match the target computer ? I managed to get SQL to be shared by TCP/IP ... how can i make it install and i dont know pop up a connection menu...that will configure all objects in the database..&lt;/p&gt;
&lt;p&gt;Thanks, Pedro&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9917546</link><pubDate>Wed, 04 Nov 2009 21:05:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9917546</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Pedro,&lt;/p&gt;
&lt;p&gt;Once you have the database running on the remote machine you change the connection string in your application to point to the remote database. Make sure you store connections strings in your application Settings (app.config) file and then you can change it without having to recompile the application. If you're using the designers to model your database then they will create a connection sting in the app.config.&lt;/p&gt;
&lt;p&gt;For more information :&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/a65txexh.aspx"&gt;http://msdn.microsoft.com/en-us/library/a65txexh.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;-B&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9934551</link><pubDate>Wed, 09 Dec 2009 13:06:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9934551</guid><dc:creator>Georges</dc:creator><description>&lt;p&gt;Beth , please i need to install sql express and attach the mdf file to it automatically without installing management studio &amp;nbsp;i know you can help me its very urgent . thank you a lottttttt in advance&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9934654</link><pubDate>Wed, 09 Dec 2009 16:50:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9934654</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi Georges,&lt;/p&gt;
&lt;p&gt;I'm not sure why you can't use the sqlcmd above. More info is here: &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms165673.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms165673.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you have a single-user app, you may also want to look into user instances, which will auto attach when your application runs:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms254504.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms254504.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HTH,&lt;/p&gt;
&lt;p&gt;-B &lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9935662</link><pubDate>Fri, 11 Dec 2009 13:51:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9935662</guid><dc:creator>georgenaffah</dc:creator><description>&lt;p&gt;Dear beth everything is working fine but still one issue , when you install sql server management studio , &amp;nbsp;before it launches it shows you the connect to server dialog box , from where you can see the server name example :george/sqlexpress , how can i get the name of the computer automatically , if i want to install sqlexpress and attach a database to it automatically and on a different computer . Please Helpppp thank you in advance for your support &lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9935672</link><pubDate>Fri, 11 Dec 2009 14:20:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9935672</guid><dc:creator>georgenaffah</dc:creator><description>&lt;p&gt;Beth I have created a batch file with the following script :&lt;/p&gt;
&lt;p&gt;sqlcmd -S .\SQLEXPRESS -george -i sqlscript\createattach.sql&lt;/p&gt;
&lt;p&gt;pause&lt;/p&gt;
&lt;p&gt;that runs the createattach sql script that is : &lt;/p&gt;
&lt;p&gt;USE [master]&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;CREATE DATABASE [Data2] ON &lt;/p&gt;
&lt;p&gt;( FILENAME = N'C:\Program Files\week Publishers\Sader Civil Cassation\Cassation Data\Data\Data2.mdf' ),&lt;/p&gt;
&lt;p&gt;( FILENAME = N'C:\Program Files\week Publishers\Sader Civil Cassation\Cassation Data\Data\Data2_log.ldf' )&lt;/p&gt;
&lt;p&gt; FOR ATTACH&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;if exists (select name from master.sys.databases sd where name = N'Data2' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) &lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;USE [master]&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;CREATE LOGIN [sadd] WITH PASSWORD=N'1p@ssw0rd', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;EXEC master..sp_addsrvrolemember @loginame = N'sader', @rolename = N'sysadmin'&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;USE [master]&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;what shall i do after ? help&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9935782</link><pubDate>Fri, 11 Dec 2009 17:09:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9935782</guid><dc:creator>Beth Massi</dc:creator><description>&lt;p&gt;Hi georgenaffah,&lt;/p&gt;
&lt;p&gt;As I mention in the article above:&lt;/p&gt;
&lt;p&gt;&amp;quot;You can use the .\ (dot-backslash) syntax to indicate the local server default instance&amp;quot;&lt;/p&gt;
&lt;p&gt;Regarding your script, I don't know what you're trying to do afterwards. You should check out the reference I mention above: &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms165673.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms165673.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Attaching a Local SQL Server Database Using sqlcmd</title><link>http://blogs.msdn.com/bethmassi/archive/2008/12/18/attaching-a-local-sql-express-database-using-sqlcmd.aspx#9936026</link><pubDate>Sat, 12 Dec 2009 06:58:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9936026</guid><dc:creator>georgenaffah</dc:creator><description>&lt;p&gt;Dear Beth&lt;/p&gt;
&lt;p&gt;all what i want to do is to install sql server express 2005 on a new machine then use the script to attach the database automatically , help me please locate where to write the .\ in order to create the server instance automatically . thank you in advance for all your support .&lt;/p&gt;
</description></item></channel></rss>