creating a simple database from scratch with sql and c#

Started by
10 comments, last by JonathanCCC 15 years, 10 months ago
hi all, i'm wondering if anyone can point me to an online tutorial, i have sql express 2005 and visual c# 2008 and am wanting to try and make a database from scratch. the books i have on the subject all show me how to connect and modify stuff in the example "northwind" database, but not how to setup an empty database ready for use. any links would be appriciated. thank you.
Advertisement
Are you wanting to create a brand new database from scratch and then access it using a C# program, or write a C# program capable of creating a new blank database on a server for you?

This isn't completely clear, I'm afraid.
i want to write a c# program, design the user interface, then bind the textboxes to the new database columns that are created within visual studio as a new sql database, so that when i run the program it's empty, but i can enter, save data etc on the database.

You'll have to forgive me if i'm not making any sense as i'm not entirley sure how it works, i have all the code that tells me how to do things like add records, delete, search and so on but not how to start a blank c# database program
Search the SQL Express documentation how to do it. It's actually pretty straightforward, once you learn the basics.
where is that documentation? on msdn? I can't find it
THIS may help you out....

OR YOU CAN CLICK ME ALSO FOR THE DOCUMENTATION
Connector/Net can do all of that for you. Few simple commands to get connected the the database and then you construct SQL queries and it passes them along to the database. I had a program creating/reading/writing to tables in like an hour or so with no previous experience with MySQL.
--------Ratings - Serious internet buisness
Quote:Original post by JonathanCCC
i want to write a c# program, design the user interface, then bind the textboxes to the new database columns that are created within visual studio as a new sql database, so that when i run the program it's empty, but i can enter, save data etc on the database.

You'll have to forgive me if i'm not making any sense as i'm not entirley sure how it works, i have all the code that tells me how to do things like add records, delete, search and so on but not how to start a blank c# database program


Ah, I see. I did something similar for a lab assignment recently except I was using VB. I've hardly touched C# except with XNA so I can't really help you there. Our database was stored on a separate server and we had the login details for it, so all we had to do was open a connection inside the program to do what we needed to do with the database.

The actual code required to access a database, view records, update records etc. is actually pretty straightforward. Pretty much everything you need is inside the .Net framework somewhere, it's just a case of knowing what to do and when. There's plenty of data binding options available, except I didn't use them; I created strings programatically which were SQL queries, then you can pass the query string to the SqlDataAdapter which will then execute it for you...

It's easier than you might have thought at first, especially if you're doing it as a personal project and not some business-critical $1m enterprisey thing.
"Head First C#" goes step by step how to do this in the first chapter of the book if I remember correctly. It's pretty cool and so simple I could probably recite the steps from memory but don't have time right now.
Also I'm pretty sure the Micrsosoft visual studio website has a video on it. They got video's for everything nowadays you can check out and that'd be the easiest for sure!
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
many thanks for the replies.

I went on an followed this tutorial:

http://support.microsoft.com/kb/307283

however when I click "create database" on my form, I get the following error:

System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at WindowsFormsApplication1.Form1.btnCreateDatabase_Click(Object sender, EventArgs e) in C:\Documents and Settings\Tony\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs:line 38


does anyone know how to fix this? i'm using windows XP media edition and visual c# 2008 and sql server express 2005 with service pack 2. I have all admin rights.

This topic is closed to new replies.

Advertisement