dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersAnu George
NareshGodera
N. KUMAR
Naveen
Mahesh
Shesh Kumar Mishra
Pawan Awasthi
saranya
raju
Anil Kumar Pandey
sudheera
More...




Resources » Code Snippets » ADO.NET


SQLDMO Create Sql server Database C# code


Posted Date:     Category: ADO.NET    Rating: 1 out of 5
Author: Member Level: Silver    Points: 7


Sample code to create an sql server Database using SQLDMO Library.
Add 'SQLDMO.dll' refference to your Project



public bool CreateDb(string serverName, string Uid, string Pwd, string dbName)
{
bool result = true;

SQLDMO.SQLServer gSQLServerDMO = new SQLDMO.SQLServer();
SQLDMO.Database nDatabase = new SQLDMO.Database();
SQLDMO.DBFile nDBFileData = new SQLDMO.DBFile();
SQLDMO.LogFile nLogFile = new SQLDMO.LogFile();


try
{
gSQLServerDMO.LoginSecure = true;
gSQLServerDMO.Connect(serverName, Uid, Pwd);

nDatabase.Name = dbName;

nDBFileData.Name = dbName;

nDBFileData.PhysicalName = gSQLServerDMO.Registry.SQLDataRoot + "\\DATA\\" + dbName + "_Data.mdf";

nDBFileData.PrimaryFile = true;

nDBFileData.Size = 2;

nDBFileData.FileGrowthType = SQLDMO.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB;

nDBFileData.FileGrowth = 1;

//Add the DBFile object

nDatabase.FileGroups.Item("PRIMARY").DBFiles.Add(nDBFileData);
//

nLogFile.Name = dbName + "Log";

nLogFile.PhysicalName = gSQLServerDMO.Registry.SQLDataRoot + "\\DATA\\" + dbName + "_Log.ldf";

nLogFile.Size = 2;

nDatabase.TransactionLog.LogFiles.Add(nLogFile);

gSQLServerDMO.Databases.Add(nDatabase);

MessageBox.Show("Database Created Sucessfully);

gSQLServerDMO.DisConnect();

}

catch (Exception SQLDBException)
{

MessageBox.Show(SQLDBException.Message);

result = false;

}

finally
{

}


return (result);
}




Did you like this resource? Share it with your friends and show your love!





Responses to "SQLDMO Create Sql server Database C# code"
Author: guru prasad    30 Jan 2009Member Level: Gold   Points : 1
This code is very nice to take back...

But i'm unable to add the 'SQLDMO.dll' to my project.

can you tellme the way to install & add ''SQLDMO.dll' to my project to take backup...



Author: Prajith mp    10 Feb 2009Member Level: Silver   Points : 2
you can find the SQLDMO.dll in
C:\Program Files\Microsoft SQL Server\80\Tools\Binn
or download it from
http://www.driverskit.com/dll/sqldmo.dll/3449.html

to add refference to a project
From project menu select "add refference" -> select the browse tab and select the dll file from the location and add to the project






Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Writing a DataTable into a text file
    Previous Resource: Copy Databases using SQLDMO
    Return to Resources
    Post New Resource
    Category: ADO.NET


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Sql server Database  .  Create  .  SQLDMO  .  

    My Profile

    Active Members
    TodayLast 7 Daysmore...


    Awards & Gifts


    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.