i have one Database i want Create Script File of this DataBase
please Give Answer
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Feb 3, 2015, 2:23 AM
Here is an example for Generating Database Script by using visual studio 2010:
The first step is to add the project references to the SMO DLL's. These can be found in the C:\Program Files\Microsoft SQL Server\110\SDK\Assemblies directory. You'll need to add references to the following DLL's:
• Microsoft.SqlServer.ConnectionInfo.dll •
Microsoft.SqlServer.Smo.dll •
Microsoft.SqlServer.SmoEnum.dll
Then add this reference:
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Sdk.Sfc;
Now you could test below code in the Page_Load() function:
protected void Page_Load(object sender, EventArgs e)
{ Server myServer = new Server("YouSQLServerName");
Scripter scripter = new Scripter(myServer);
Database myAdventureWorks = myServer.Databases["YourDatabaseName"];
Urn[] DatabaseURNs = new Urn[] { myAdventureWorks.Urn}; StringCollection scriptCollection = scripter.Script(DatabaseURNs);
foreach (string script in scriptCollection)
{ Response.Write(script);
Response.Write("
"); } }
For further information, you could access to the below link:
http://www.mssqltips.com/sqlservertip/1833/generate-scripts-for-database-objects-with-smo-for-sql-server/
http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated
http://technet.microsoft.com/en-us/library/ms162153(v=sql.105)
Saber ShaikhPosted Feb 3, 2015, 2:15 AM
Munesh SharmaPosted Feb 3, 2015, 2:12 AM
Munesh SharmaPosted Feb 3, 2015, 2:12 AM
Joginder BangerPosted Feb 3, 2015, 1:28 AM
click here
and more link here