So this is where the SMO objects come in, I have gone through the Hands on labs for SQL 2005 that I was pointed to at Teched, but these only cover the full version not Express.
All I need is a simple script that will show me how to connect to the Database file. If I could get a simple script that would say return the names of the tables in the file that will get me started.|||Take a look at http://blogs.msdn.com/mwories/articles/smosample_transfer.aspx. This sample explains how to generate a script for a given database with SMO. SMO works with Express, so I do not know what limitation you are running in. Can you elaborate?|||My problem is how to connect to the actual file in the connection objects.
// Setup source connection (in this sample source is .\inst1 and target is '.' (the default instance)
Server svr = new Server(@.".\inst1");
Database db = svr.Databases["testdb"];
With the above code, if I have a Visual Studio project that is located c:\projects\test, and the mdf file is located here c:\projects\test\data\test.mdf.
How do I connect to that file, I want to create an application that will allow me to pass a file location (Like "C:\projects\test\data\test.mdf") and have it script out the Database structure including any Stored procs and such to an SQL file that I can execute against another database at a later stage. But I can not build the connection object to connect to the express file.
I have VS 2005 RC Installed if that helps, but I also plan to use this on the express IDEs (C#, and Web Developer)
|||I have put together this simple script to list the databases on the express server,Server sqlserver = new Server(".\\SQLExpress");
foreach (Database d in sqlserver.Databases)
{
Console.WriteLine(d.Name);
}
I think that I need to attach the file to the Database engine before the SMO Objects can read it. Could someone please assist in a sample script on how to attach "test.mdf" so that it will appear in the list that the above script returns.
No comments:
Post a Comment