none
how to attach sql database file to creating .exe setup in c#

    Question

  • how i can attach a sql server 2008 r2 databse (.mdf) on creating setup

    and also i want to know that after this 

    on installing the application on another system

    (there must be sql server 2008 installed on that system or not)????

    and how i can create a application like other softwares that uses databases but no require any framework 

    or any reqirement like (Inflow inventory software)...

    Wednesday, December 04, 2013 6:20 PM

Answers

  • Hi abhijeeet,

    The client machine does not require SQL server to be installed but there must be a SQL Server somewhere for the client's machine to use, if your application uses SQL Server to store its data.

    Where your client's machine can connect to:
    • possibly on his machine (if this is just a trial, for instance)
    • possibly on a server in his network (if multiple users in his organization will want to use the data)
    • possibly in the cloud (think: SQL Azure)

    The MSSQL  database can automatically attached while running the setup file in .Net. Its Just simple. Follow the things:

    We can implement auto attach  database just use the connection string following.

    1)      Add a folder  named ”DB” to the project, and copy the database  file into it after you detach it from your sql  server.

    2)      Change your connection string like this:
        <connectionStrings>
            <add name="WindowsFormsApplication1.Properties.Settings.BabakConnectionString"
                connectionString="Data Source=.;AttachDbFilename=|DataDirectory|\DB\Babak.mdf;
                Initial Catalog=test;Integrated Security=True"
                providerName="System.Data.SqlClient" />
        </connectionStrings>


    3)      After these, the database file  will auto attach to the sql server  when you run your application, and the database name is “test”, you can open the sql server management studio to find it.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 05, 2013 5:49 AM
    Moderator
  • You apparently do not want to use a a Database server, wich means you want to use a Embedded Database.

    http://en.wikipedia.org/wiki/Embedded_database

    How to add teh file to the setup? Just like any other file! And that depends on what Programm you use to make your setup (wich you have not told us).

    Note that you should consider storing the DB in the ApplicationData or userspecific applciation Data Folders. You have no guarantee that you can write files in the Programm folder on any computer since Windows XP. But you are guaranteed access to the ProgrammData and Userprofiles AppDataFolders.

    You can get the paths via Specialfolders Enumeration (never expect those paths to be static):

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Wednesday, December 04, 2013 10:03 PM

All replies

  • but there is no any link which explains how to add database to setup

    and also i want to know that after this 

    on installing the application on another system

    (there must be sql server 2008 installed on that system or not)????

    and how i can create a application like other softwares that uses databases but no require any framework 

    or any reqirement like (Inflow inventory software)...

    Wednesday, December 04, 2013 7:37 PM
  • You apparently do not want to use a a Database server, wich means you want to use a Embedded Database.

    http://en.wikipedia.org/wiki/Embedded_database

    How to add teh file to the setup? Just like any other file! And that depends on what Programm you use to make your setup (wich you have not told us).

    Note that you should consider storing the DB in the ApplicationData or userspecific applciation Data Folders. You have no guarantee that you can write files in the Programm folder on any computer since Windows XP. But you are guaranteed access to the ProgrammData and Userprofiles AppDataFolders.

    You can get the paths via Specialfolders Enumeration (never expect those paths to be static):

    http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Wednesday, December 04, 2013 10:03 PM
  • Hi abhijeeet,

    The client machine does not require SQL server to be installed but there must be a SQL Server somewhere for the client's machine to use, if your application uses SQL Server to store its data.

    Where your client's machine can connect to:
    • possibly on his machine (if this is just a trial, for instance)
    • possibly on a server in his network (if multiple users in his organization will want to use the data)
    • possibly in the cloud (think: SQL Azure)

    The MSSQL  database can automatically attached while running the setup file in .Net. Its Just simple. Follow the things:

    We can implement auto attach  database just use the connection string following.

    1)      Add a folder  named ”DB” to the project, and copy the database  file into it after you detach it from your sql  server.

    2)      Change your connection string like this:
        <connectionStrings>
            <add name="WindowsFormsApplication1.Properties.Settings.BabakConnectionString"
                connectionString="Data Source=.;AttachDbFilename=|DataDirectory|\DB\Babak.mdf;
                Initial Catalog=test;Integrated Security=True"
                providerName="System.Data.SqlClient" />
        </connectionStrings>


    3)      After these, the database file  will auto attach to the sql server  when you run your application, and the database name is “test”, you can open the sql server management studio to find it.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, December 05, 2013 5:49 AM
    Moderator