473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Sql Server express 2005 deployment

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.

Jul 16 '07 #1
10 6057
>
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.

Jul 17 '07 #2

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

"Mr. Arnold" wrote:
>

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.

Jul 17 '07 #3

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]


"Punit Kaur" wrote:
>
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

"Mr. Arnold" wrote:
>
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.
Jul 17 '07 #4

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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\
"Mr. Arnold" wrote:
>

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.

Jul 17 '07 #5

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" wrote:
>
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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\
"Mr. Arnold" wrote:
>
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.
Jul 17 '07 #6
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" wrote:
>
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" wrote:

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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\
"Mr. Arnold" wrote:
>

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.
>
>
Jul 17 '07 #7

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" wrote:
>
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" wrote:

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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\
"Mr. Arnold" wrote:
>

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.
>
>
Jul 17 '07 #8

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" wrote:
>
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" wrote:

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" wrote:
>
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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\
>
>
"Mr. Arnold" wrote:
>

>
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.
Jul 18 '07 #9

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" wrote:
>
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" wrote:

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" wrote:
>
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" wrote:
>

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=|DataDirecto ry|\\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_wo rking\RM\MonitorApp\MonitorApp\MonitorApp.mdf;Inte grated 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\


"Mr. Arnold" wrote:

>

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.
>
>
Jul 18 '07 #10
Use a connection string that looks like this:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|
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

On Jul 18, 1:24 pm, Punit Kaur <PunitK...@discussions.microsoft.com>
wrote:
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.NET2005.

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
Jul 30 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bernie | last post by:
I am a long time VB 6 developer and am using VB.NET 2005 Express. I have written a small app that I want to deploy to another machine. I can't find any documentation that relates to the express...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
8
by: nick | last post by:
I have only SQL Server 2005 installed on my PC. And I tried to add the following rows in web.config to use SQL Server 2005 instead of Express: <connectionStrings> <clear /> <add...
0
by: Steve | last post by:
Hi All I have a vb.net Windows forms App which I am deploying with a VS.net 2005 deployment project I have selected SQL Server express as a prerequisite and use the standard SQL server express...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
by: Ted | last post by:
I am working on two versions of an application, one of which will be a windows forms application (which will need to be redistributable) and the other will be a web application. I have MS Visual...
3
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I...
4
by: Preben Zacho | last post by:
Hi there The scenario I got is this: I have created a Windows application in VS and I want to deploy it to another machine running Windows Vista. Since I have no control over this other machine,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.