From: RayLopez99 on
Using the Wizards (drag and drop from toolbox) in Visual Studio 2008,
does anybody know a quick way to repoint or redo the connection string
so that it points to the right database?

Here's the problem:

Say you have a database in c:\Directory1\NORTHWND.MDF.

Now your connection string points to it. Everything works fine, the
program (a web app using ASP.NET) works fine.

You move the database to c:\Directory2\NORTHWND.MDF

But changing globally the connection strings from "Directory1" to
"Directory2" (doing a global search and replace) gives a runtime error
('database could not be opened..." etc).

So I guess I have to drag and drop connection strings 'by hand' and
restart all over again, which is tedious since the Wizard also asks
you to redo the SQL query associated with the connection string...

I'm confident after a few hours I'll get it to work, but is there a
quicker way and does this problem ring a bell?

Also, as a bonus followup question: suppose I get this program to
work on my local drive. Now I want to make the database reside on a
network drive. The network is supported by an IT guy who is not that
knowledgeable about databases. What's the minimum I need to tell him,
and again, do I need to replace and redo "the hard way" all connection
strings? What would be the path I use, or is the program smart enough
to figure out to search the entire LAN?

This is a web app, using Visual Web Developer under Visual Studio 2008
SP1 and SQL Server Express 2005.

RL
From: RayLopez99 on
On Feb 8, 5:47 am, RayLopez99 <raylope...(a)gmail.com> wrote:

> Also, as a bonus followup question:  suppose I get this program to
> work on my local drive.  Now I want to make the database reside on a
> network drive.  The network is supported by an IT guy who is not that
> knowledgeable about databases.  What's the minimum I need to tell him,
> and again, do I need to replace and redo "the hard way" all connection
> strings?  What would be the path I use, or is the program smart enough
> to figure out to search the entire LAN?
>
> This is a web app, using Visual Web Developer under Visual Studio 2008
> SP1 and SQL Server Express 2005.
>

I have a partial answer to this last question, from a book:
"Generally, a better option is to include the local database files in
the directory structure of your web project--specifically, putting the
database files in the App_Data of your web application"--that way your
code can access this database easily.

RL
From: RayLopez99 on
On Feb 8, 7:49 am, RayLopez99 <raylope...(a)gmail.com> wrote:

I figured out my problems, and just to complete this thread here are
the solutions:

1) you have to install SQL Server 2008 when working with Visual Studio
2008. That solved most of the problem #1.

2) as a bonus, I figured out a trick on how to use a relative path to
store your database, so that deploying it in a LAN is easy. From this
blog post (and it is undocumented):
http://www.develop-one.net/blog/2006/09/05/RelativePathInWebApplicationConnectionString.aspx

The trick is this: using the term "=|DataDirectory|" will reference
the directory "App_Data" found in ASP.NET projects (and the
conventional place to put data).

So, suppose your database was called "myDatabase1", and your
Web.config file had this entry:

<connectionStrings>
<add name="myDataBaseConnectionString" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\HardCodedDirectory
\myDataBase1.mdf&quot;;Integrated Security=True;Connect
Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>



you would copy the database into your \App_Data folder found in the
app's root directory, then substitute this connection string (in
Web.config) to reference the database, which now resides under the
app's root directory, in \App_Data. Problem #2 solved, since no need
for an absolute file path, which is tricky in a LAN:



<connectionStrings>
<add name="myDataBaseConnectionString" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=&quot;|DataDirectory|
myDataBase1.mdf&quot;;Integrated Security=True;Connect Timeout=30;User
Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>


RL
From: Jay on
> 2) as a bonus, I figured out a trick on how to use a relative path to
> store your database, so that deploying it in a LAN is easy. From this
> blog post (and it is undocumented):
> http://www.develop-one.net/blog/2006/09/05/RelativePathInWebApplicationConnectionString.aspx
>
> The trick is this: using the term "=|DataDirectory|" will reference
> the directory "App_Data" found in ASP.NET projects (and the
> conventional place to put data).

I was of the impression that programs dealt with things like this by having
an include file (or whatever it's called in your language) that had platform
specific information in it, like a .ini file, or the registry entries.


From: RayLopez99 on
On Feb 8, 5:25 pm, "Jay" <s...(a)nospam.org> wrote:
> > 2) as a bonus, I figured out a trick on how to use a relative path to
> > store your database, so that deploying it in a LAN is easy. From this
> > blog post (and it is undocumented):
> >http://www.develop-one.net/blog/2006/09/05/RelativePathInWebApplicati...
>
> > The trick is this:  using the term "=|DataDirectory|" will reference
> > the directory "App_Data" found in ASP.NET projects (and the
> > conventional place to put data).
>
> I was of the impression that programs dealt with things like this by having
> an include file (or whatever it's called in your language) that had platform
> specific information in it, like a .ini file, or the registry entries.

Web.config is the file this string appears in, so it's similar to what
you have in mind.

RL