Ok...I have a very basic question...how do I attach my database when I'm turning my c#.net code into a setup file?
I'm just learning and I'm sorry if you feel this a too basic question...:)

>I'm just learning and I'm sorry if you feel this a too basic question.

In fact, your question is not basic. I would like to suggest you to read this article thoroughly.

If you decide to write a database installer, you must first choose a technology on which to base the installer. In Windows, the most common types of application installers are MSI files, which you can build using Visual Studio® .NET or third-party products such as InstallShield Developer or Wise for Windows Installer

With visual studio, you have an option of creating setup project/merge module project/cab project. But I think as per your question of deploying an exe, set up project would work for you.
Setup projects allow you to create installers in order to distribute an application. The resulting Windows Installer (.msi) file contains the application, any dependent files, information about the application such as registry entries, and instructions for installation. When the .msi file is distributed and run on another computer, you can be assured that everything necessary for installation is included; if for any reason the installation fails (for example, the target computer does not have the required operating system version), the installation will be rolled back and the computer returned to its preinstallation state. Check the detailed steps for creating this at: http://msdn.microsoft.com/en-us/library/996a3fxs(VS.80).aspx

Also, to streamline your database to be included in the installer, you have to study the detailed steps at: http://msdn.microsoft.com/en-us/magazine/cc163919.aspx

well I solved upto the last part of adding prerequisites,but now I have a database which gets attached to the program when it runs in my computer,but when I try to install the program in another one,the error msg of no database attached is shown.
plz help.
thank you.

You must have a database server installed on target machine.

I'm working with microsoft sql server on my own pc.
can i attach my database files( .mdf and .ldf )to my code when I'm publishing it and create an instance of it?
I asked one of my teachers who said I can attach my database files by firing a try catch statement and putting the store procedure of attach database into my first form...
is it possible to do so?I'm really not getting any effective solution by trying that out.
it is a bit difficult for me to add those database files into the client machine...so is there any other way out?
Thank you. :)

it is a bit difficult for me to add those database files into the client machine...so is there any other way out?

You didn't read my post #2 and #5.

Excert from the article - http://en.csharp-online.net/Deploying_Windows_Applications%E2%80%94Prerequisites

SUMMARY:
SQL Server 2005 Express Edition: If you need a database on the client system, you can include the SQL Server 2005 Express edition with the setup program.

You can embed SQL server express into custom applications.

I think you are referring to the fact that while adding the prerequisites I should add SQL version 2.0,that I have done...but I also need to attach my own tables which I'm not being able to do...
How do I attach my own tables to the setup file while creating my software?
Thank You.:)

>How do I attach my own tables to the setup file while creating my software?

You can't attach tables but you can add database files (.mdf, .ldf) into installer.

yes I have done that..and when i work on my machine which contains the database it works fine.
but if i go on to any other machine....the error msg shows that there is no database tables for it to enter data into...
I'm not sure why after attaching both mdf and ldf files the program gives such an error...

>but if i go on to any other machine....the error msg shows that there is no database tables for it to enter data into...

Maybe you had deployed an empty database.

Solved it. :)
Thank You everyone. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.