Ok, that's good. You can now attach the database bak file to your
installation package. To make an installation package use the build in setup
& deployment install wizard that steps through all the settings. When
prompted to select what additional files to bundle up with the package,
select your SQL database backup file.
If size is an issue, you can also create a script file of your database. Use
SQL Server Management Studio to log in and right click on the database you
want to deploy. Select "Script Database As"->"Create To"->"File" and then
save the file. This file contains the code to recreate your database and
takes less space than the previous method. Add the file to your install
wizard by using the same steps as above.
Ok, now that you have an installation package you can now install your
program + database file to the host computer. Obviously the client will need
SQL Server 2005 installed on their end for this to work. With the database
bak or script file on the client computer you need to log into SQL Server
Management Studio on the client and either use the bak file to restore the
database from the backup or run the script file to produce a new database.
Both options are manual. When done, update you application's config file to
point to the new database server - you only need to change the "Data Source"
string in the connection string. That's it.
To make this automatic, I think you need to make a custom dll that launches
during installation and runs the script to create the database. This might
run into security problems though and you would also need to know the name of
the database server to install to and at the end change the application
config file.
Adrian.
--
[Please mark my answer if it was helpful to you]
Punit Kaur said:
Alright , I have connected to the actual database and I also made a backup.
The backup generates a .bak file. The mdf and ldf files were already created
when I created the database. Back up created only one .bak file. What do I do
now?
Also can you please tell me about any free installer package where I could
include these files. Or does one come with the VS 2005? If yes, where can I
find it. Any tutorial on how to proceed with this?
Thanks a lot.
Adrian Voicu said:
You don't have to create a local database in this case. In the connection
string you should only specify the name of the server where the database is
and not the path to the mdf. So connect to the actual database when you
develop your code. When you are done, make a backup of your sql database,
take the mdf + ldf files that you created with the backup and attach them to
your installation package.
Adrian.
----
[Please mark my answer if it was helpful to you]
:
Thanks for the suggestion. I created a local database using Add new item in
VS .NET and created a table. Now I am having trouble with the Connection
String.
When I used the following connection string which has the relative path to
the file:
public const string DB_CONN_STRING = "Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\MonitorApp.mdf;Integrated Security=True;User Instance=True";
and try to insert into the table.. it does not do anything. It also does not
throw any exception when I execute the following stmt:
myCommand.ExecuteNonQuery();
which is enclosed within a try block
When I hard coded the connection string to point to the .mdf file by giving
the exact path..
Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\current_working\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Integrated Security=True;User Instance=True
I was able to succefully insert in to the table.
So It means there is something wrong in the relative path that uses
|DataDirectory|.
Can someone please point out if you see anything wrong....
The path of my VS.NET project's solution is C:\current_working\RM\MonitorApp\
I think I need to make sure that the relative path works fine... so as to be
able to correctly deploy sql server express.
Please suggest.
Thanks a lot.
C:\current_working\RM\MonitorApp\MonitorApp\
:
Do I have to create a .mdf file or does SQL Sever 2005 automatically
create
one when I create a database. If yes where does it save the file. And then
what are the next steps after having an existing .mdf file...
The MDF and LDF files are going to be located at Program Files/Microsoft Sql
Server/MSSQL.1/MSSQL/DATA.
As far as the rest of the stuff about deployment of a .Net solution using MS
Sql Server Express, I ran across articles out there on Google showing the
how to.