Click here to Skip to main content
15,906,463 members
Home / Discussions / Database
   

Database

 
GeneralRe: db4o Embedded DB Pin
PIEBALDconsult1-Aug-10 4:11
mvePIEBALDconsult1-Aug-10 4:11 
GeneralRe: db4o Embedded DB Pin
Mike Hankey1-Aug-10 4:18
mveMike Hankey1-Aug-10 4:18 
GeneralRe: db4o Embedded DB Pin
Dan Mos1-Aug-10 5:20
Dan Mos1-Aug-10 5:20 
GeneralRe: db4o Embedded DB Pin
Mike Hankey1-Aug-10 5:31
mveMike Hankey1-Aug-10 5:31 
GeneralRe: db4o Embedded DB Pin
Dan Mos1-Aug-10 5:39
Dan Mos1-Aug-10 5:39 
QuestionInsert and delete Pin
T.RATHA KRISHNAN31-Jul-10 1:52
T.RATHA KRISHNAN31-Jul-10 1:52 
AnswerRe: Insert and delete Pin
Eddy Vluggen31-Jul-10 2:19
professionalEddy Vluggen31-Jul-10 2:19 
QuestionThis May Be A Stupid Question But... [modified] Found It! Pin
Roger Wright30-Jul-10 20:14
professionalRoger Wright30-Jul-10 20:14 
I'll ask it anyway, having already tried Google and MSDN.

I'm fiddling with a SQL Server app to track substation equipment - one of several projects I'm working on. I've got a skeleton working on a local instance of SQL Server Express, but I'm thinking ahead to the day I deploy this on the company server, which has the full version of SQL Server installed. I don't want to manually recreate the database on the server - that way madness lies - and I don't want to Export/Import my existing database, as it's full of test cases I don't want to have to delete. I'm sure there's a nice, efficient way to create a database in SQL Server programmatically when my app runs for the first time, but I haven't a clue how to do it. Google returns a plethora of responses, enough to completely confuse me, and MSDN returns none of any relevance - the usual ratio.

Can someone point me to a tutorial of some sort that my aged brain can comprehend?

[EDIT]

While MSDN didn't help, I finally asked the right question in Google - which led straight back to Microsoft, of course:

using System;
using System.Data.SqlClient;
    String str;
    SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated               security=SSPI;database=master");

    str = "CREATE DATABASE MyDatabase ON PRIMARY " +
        "(NAME = MyDatabase_Data, " +
        "FILENAME = 'C:\\MyDatabaseData.mdf', " +
        "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
        "LOG ON (NAME = MyDatabase_Log, " +
        "FILENAME = 'C:\\MyDatabaseLog.ldf', " +
        "SIZE = 1MB, " +
        "MAXSIZE = 5MB, " +
        "FILEGROWTH = 10%)";

    SqlCommand myCommand = new SqlCommand(str, myConn);
    try 
    {
        myConn.Open();
	myCommand.ExecuteNonQuery();
	MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK,    MessageBoxIcon.Information);
    }
    catch (System.Exception ex)
    {
	MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    finally
    {
	if (myConn.State == ConnectionState.Open)
	{
	    myConn.Close();
	}
    }


Sorry about the formatting - that's Opera at work...

The article further states that, if I want just to use the Model database, eliminate all the crud and use simply, str = "CREATE DATABASE MyDatabase".

I haven't tried it yet as it's getting rather late, but I think I'll play a bit later this week. I presume that I can then use CREATE TABLE and all its sundry relatives to fill out the details once this part works, and I've already found a way to enumerate the available SQL Server instances, which will allow the end user to decide which server to host the app on.

Assuming that this works as advertised, and since it doesn't seem to be common knowledge, I suspect that it will make a decent article or tip. Big Grin | :-D

By the way, the article is located at: support.microsoft.com[^]

[/EDIT] We now return you to our regular programming...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
modified on Wednesday, August 4, 2010 1:47 AM

AnswerRe: This May Be A Stupid Question But... Pin
Mycroft Holmes30-Jul-10 21:30
professionalMycroft Holmes30-Jul-10 21:30 
GeneralRe: This May Be A Stupid Question But... Pin
Roger Wright2-Aug-10 17:20
professionalRoger Wright2-Aug-10 17:20 
AnswerRe: This May Be A Stupid Question But... Pin
Peter_in_278030-Jul-10 21:58
professionalPeter_in_278030-Jul-10 21:58 
AnswerRe: This May Be A Stupid Question But... Pin
Jörgen Andersson30-Jul-10 23:40
professionalJörgen Andersson30-Jul-10 23:40 
GeneralRe: This May Be A Stupid Question But... Pin
Roger Wright31-Jul-10 4:34
professionalRoger Wright31-Jul-10 4:34 
AnswerRe: This May Be A Stupid Question But... Pin
PIEBALDconsult31-Jul-10 10:22
mvePIEBALDconsult31-Jul-10 10:22 
AnswerRe: This May Be A Stupid Question But... Pin
Corporal Agarn2-Aug-10 9:55
professionalCorporal Agarn2-Aug-10 9:55 
GeneralRe: This May Be A Stupid Question But... Pin
Roger Wright2-Aug-10 17:18
professionalRoger Wright2-Aug-10 17:18 
GeneralRe: This May Be A Stupid Question But... Pin
Roger Wright3-Aug-10 20:16
professionalRoger Wright3-Aug-10 20:16 
Questionquery takes long time! Pin
Jassim Rahma30-Jul-10 4:34
Jassim Rahma30-Jul-10 4:34 
AnswerRe: query takes long time! Pin
dan!sh 30-Jul-10 4:49
professional dan!sh 30-Jul-10 4:49 
AnswerRe: query takes long time! Pin
Eddy Vluggen30-Jul-10 5:07
professionalEddy Vluggen30-Jul-10 5:07 
GeneralRe: query takes long time! Pin
Jassim Rahma30-Jul-10 5:43
Jassim Rahma30-Jul-10 5:43 
GeneralRe: query takes long time! Pin
Eddy Vluggen30-Jul-10 6:04
professionalEddy Vluggen30-Jul-10 6:04 
GeneralRe: query takes long time! Pin
David Skelly30-Jul-10 6:12
David Skelly30-Jul-10 6:12 
GeneralRe: query takes long time! Pin
Eddy Vluggen30-Jul-10 6:29
professionalEddy Vluggen30-Jul-10 6:29 
AnswerRe: query takes long time! Pin
PIEBALDconsult30-Jul-10 19:13
mvePIEBALDconsult30-Jul-10 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.