Dynamic configuration file?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm working on an ASP.NET 2.0 site and my hosting provider has the root in a
different place than I have it locally which is not a problem for most
things, except for the access oledb database connection. If I try to specify
a relative path, it is not relative from the same point as the rest of
content (say an img src attribute) so it seems that this requires a full
absolute path. Is there a way I can pull this part of the connection string
from somewhere else such that on my machine it will point to one location
while on the hosting provider it will point to another location? Possibly
something with the new configuration API? I would imagine that this is a
common scenario for people hosting their sites on commercial providers....

Thanks...

-Ben
 
Hi Ben,
Is there a way I can pull this part of the connection string from
somewhere else such that on my machine it will point to one
location while on the hosting provider it will point to another
location? Possibly something with the new configuration API

yes, there is a new .NET 2.0 configuration
class---System.Configuration.ConnectionStringSettings, but it is used to
retrieve the connection string from the configuration file which is located
in the same directory corresponds to the web app, not from somewhere in a
remote machine's...

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Gary,

Do you have any suggestions regarding my circumstance then? For some reason,
the relative path that the database connection starts from is different than
the location of the website. On my local system, for example, it seemed to be
looking in my program files\visual studio 8\ide folder. In any case, it seems
to require a full path to the DB file and the location where the db file
lives on my remote system is beyond my control so I have tohard code it but
it happens to be residing on the D drive which is my cd rom locally so I
can't mimick the remote path locally for my database. Any suggestions?

-Ben

"Gary Chang[MSFT]" said:
Hi Ben,
Is there a way I can pull this part of the connection string from
somewhere else such that on my machine it will point to one
location while on the hosting provider it will point to another
location? Possibly something with the new configuration API

yes, there is a new .NET 2.0 configuration
class---System.Configuration.ConnectionStringSettings, but it is used to
retrieve the connection string from the configuration file which is located
in the same directory corresponds to the web app, not from somewhere in a
remote machine's...

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Ben,
On my local system, for example, it seemed to be
looking in my program files\visual studio 8\ide folder.
In any case, it seems to require a full path to the DB file
and the location where the db file lives on my remote system
is beyond my control ...

Would you please tell me which database system do you use in you web
application, if it is a SQL Server 2005, you can specify your database
server name in your connection string, if it is a SQL Server 2005 Express,
then you need to specify the full path to the target mdf file in your
working machine, but I am not very clear why it is out of your control, do
you have any difficulty to provide its absolute path?


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Gary,

I'm using an access database (OLEDB classes). When you don't specify an
absolute path, you're not using the same relative path as the rest of your
website for some reason.

To further explan, I created a simple asp.net website in VS 2005. In the
page load event, I have:

System.Data.OleDb.OleDbConnection myconn = new
System.Data.OleDb.OleDbConnection();
myconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=xc.mdb";
myconn.Open();

So now I'm using a relative path. When I execute the code, the exception
states that:

Could not find file 'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\xc.mdb'.

Notice that it is trying to find the file in the IDE folder for Visual
Studio. This is certainly not the behavior I want. The file lives in the same
folder as the website (I can put it in App_Data I guess). But, as you just
saw, I must use an absolute path.

Now that that is established, the issue is that the beginning portion of the
absolute path is not within my control as the real location of my website
folder is set by my host. (It happens to be something like
D:\Win32\Inetserv\[username]\). I could get around this entire problem if I
placed my local database file in a folder called
D:\Win32\Inetserv\[username]\. Unfortunately, D: is my cdrom drive. I could
also get around this problem by using two different configuration files, one
for local use and the other for remote. But I was wondering ifthere is
anything more elegant.

I hope this helped to clarify. Please let me know if you want further
explanation of what I'm trying to achieve.

PS: Why is the relative path the IDE folder? What thread is doing this data
access and why was this chosen as the folder? I don't see why anyone would
place the database there.

Thanks....

-Ben

"Gary Chang[MSFT]" said:
Hi Ben,
On my local system, for example, it seemed to be
looking in my program files\visual studio 8\ide folder.
In any case, it seems to require a full path to the DB file
and the location where the db file lives on my remote system
is beyond my control ...

Would you please tell me which database system do you use in you web
application, if it is a SQL Server 2005, you can specify your database
server name in your connection string, if it is a SQL Server 2005 Express,
then you need to specify the full path to the target mdf file in your
working machine, but I am not very clear why it is out of your control, do
you have any difficulty to provide its absolute path?


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Ben,
Notice that it is trying to find the file in the IDE folder for Visual
Studio. This is certainly not the behavior I want. The file lives
in the same folder as the website (I can put it in App_Data I guess).
But, as you just saw, I must use an absolute path.

It appears the relative path you put in the connection string had already
been resolved during the compilation-time. However I don't think you need
to use an absolute path to specify your database, you can use a new .NET
2.0 framework property DataDirectory to build the relative path of your web
site(for a web application, it will be the the App_Data folder ) into your
connection string, or just specify the connection string in the web.config
file by using the |DataDirectory| macro, please refer to the following blog
article for details:

Working with local databases
http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx


Wish it works!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Just what I needed!!! Thanks Gary!

-Ben

"Gary Chang[MSFT]" said:
Hi Ben,
Notice that it is trying to find the file in the IDE folder for Visual
Studio. This is certainly not the behavior I want. The file lives
in the same folder as the website (I can put it in App_Data I guess).
But, as you just saw, I must use an absolute path.

It appears the relative path you put in the connection string had already
been resolved during the compilation-time. However I don't think you need
to use an absolute path to specify your database, you can use a new .NET
2.0 framework property DataDirectory to build the relative path of your web
site(for a web application, it will be the the App_Data folder ) into your
connection string, or just specify the connection string in the web.config
file by using the |DataDirectory| macro, please refer to the following blog
article for details:

Working with local databases
http://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx


Wish it works!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top