Steps To Create A Sql Server Database

Páginas: 3 (547 palabras) Publicado: 23 de noviembre de 2012
da
This step-by-step article shows you how to create a Microsoft SQL Server database by using ADO.NET and Visual C# .NET because programmers often need to create Databases programmatically. Steps to Create a SQL Server Database

To create the database, follow these steps:
1. Create a new Visual C# .NET Windows application.
2. Place a button on Form1. Change thebutton's Name property to btnCreateDatabase, and then change the Text property toCreate Database.
3. Use the using statement on the System and System.Data namespaces so that you do not have to qualify declarations inthose namespaces later in your code. Add the following code to the General Declarations section of Form1:
4. using System;
5. using System.Data.SqlClient;


6. Switch to Form view, and thendouble-click Create Database to add the click event handler. Add the following sample code to the handler:
7. String str;
8. SqlConnection myConn = new SqlConnection("Server=localhost;Integrated security=SSPI;database=master");
9.
10. str = "CREATE DATABASE MyDatabase ON PRIMARY " +
11. "(NAME = MyDatabase_Data, " +
12. "FILENAME = 'C:\\MyDatabaseData.mdf', " +13. "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
14. "LOG ON (NAME = MyDatabase_Log, " +
15. "FILENAME = 'C:\\MyDatabaseLog.ldf', " +
16. "SIZE = 1MB, " +
17."MAXSIZE = 5MB, " +
18. "FILEGROWTH = 10%)";
19.
20. SqlCommand myCommand = new SqlCommand(str, myConn);
21. try
22. {
23. myConn.Open();
24.myCommand.ExecuteNonQuery();
25. MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
26. }
27. catch (System.Exception ex)
28. {
29.MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
30. }
31. finally
32. {
33. if (myConn.State == ConnectionState.Open)
34. {
35....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • sql server
  • Sql server
  • Sql server
  • Sql Server
  • Sql server
  • SQL Server
  • SQL SERVER
  • SQL Server

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS