Sql Server express 2005 deployment

G

Guest

Hi,

I am developing a windows application in VS.NET 2005. The application is
database driven and I need to deploy it on a client's pc. How should I go
about developing such an application. I remember I did something once long
back .. like including .mdf files into my project in the solution explorer of
VS 2005 and then used Click Once deployment tool ... to make sure that the
database and tables were created when the client installed my application.
Now I seem to have forgotten the procedure and cannot find any other
resource. Iwould be really grateful if someone could guide me through it.

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...

Thank you.
 
M

Mr. Arnold

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.
 
G

Guest

Ya I tried to do that... going to the folder and selecting the mdf file....
it said "An error occurred"... i will try it gain tomorrow.

Thank you
 
G

Guest

When you want to deploy your sql database with a project, you need to make a
backup of your database. When you make the back up, create the mdf and the
ldf files. Take these copies and deploy them with your application. You
cannot copy the mdf or ldf files while SQL is running. You need to stop the
SQL Server process before you can do that.

Adrian.
[Please mark my answer if it was helpful to you]
 
G

Guest

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\
 
G

Guest

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.
 
G

Guest

I am unable to understand one thing....

Like you suggested, If I have to connect to the specific server on my local
machine.. the connection string would be specific to my machine. So when I
attach the mdf and ldf files.. when the customer is installing it on his
machine, how will the application connect to that database... since it will
need to use a different connection string. Can I provide the DB connection
string in the installation package? I have never done this before so I have
no idea!!

Thanks




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]



Punit Kaur said:
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\
 
G

Guest

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]



Punit Kaur said:
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\
 
G

Guest

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]



Punit Kaur said:
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.
 
G

Guest

Hi,

Thank you for the detailed steps. From your answer I infer that the client
will need to manually do things which is not my intention. I remember doing
it in an easier way where I did not even need to do anything manually except
for installing the .msi package that had the database .mdf files along with
all the other components like .net 2 framework besides the actual
application. Also since the connection string was relative and I am using
"localhost" instead of my machinename, I had no problems installing and
running the application. I remember I had used the "Publish" wizard in VS.NET
2005.

However, since now I am having connection string problems when I am using
|DataDirectory| in the connection string to access .mdf file... I thought
that the solution you were giving would not require the client to do anything
once I attached .mdf files.

Is there any way besides the custom dLL solution where we can do it without
having to restore the database or do anything manually on the clients
computer?

Thanks



Adrian Voicu said:
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.
 
A

ainsleyp

Use a connection string that looks like this:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|
MyDatabase.mdf;User Instance=True;Integrated Security=True

This will attach using a user instance. That means you don't have to
do anything manual like attaching the database in SQL Server
Management Studio. You just include Sql Server 2005 Express in the
installation (it's even in the Prerequisites list in your Setup
project so you just have to check a box), and just include the
database files with the setup.

It makes it difficult to remotely connect into the database, but if
you don't need to do that then stick with user instances. They're
quite convenient.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top