|
-
Nov 2nd, 2004, 06:17 PM
#1
Thread Starter
Hyperactive Member
[solved] a question about deployment of database in ASP.net
i have a Access database, the connection string is:
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C: \Inetpub\wwwroot\MyBooks\MyBooksDB.mdb"
When I run it on local machine, everything is ok. The mdb file is under website's root \MyBooks\
now I deploy it to the a host, it reports error about the database. obviously, it can not find the mdb file. How can I change the connection string?
thx
Last edited by temp_12000; Nov 2nd, 2004 at 07:39 PM.
-
Nov 2nd, 2004, 06:36 PM
#2
Frenzied Member
Lots of ways, perhaps the easiest is to stick it in your web.config file and access it from there. Add something like this to your web.config
Code:
<appSettings>
<add key="database_connection_string" value="Persist Security Info=False;Integrated Security=SSPI;database=PatriotDispatch;server=MIKELAP"/>
</appSettings>
</configuration>
Obviously, change the value to whatever you need. Then, you access it in your code something like:
Code:
myConnectionString = ConfigurationSettings.AppSettings["database_connection_string"];
Sorry, that's C#, don't have a VB.NET example handy, but you get the idea. You can search MSDN for ConfigurationSettings to get some sample code.
This way, your end user can change the config file whenever needed, and you don't need to hard code.
-
Nov 2nd, 2004, 07:28 PM
#3
Thread Starter
Hyperactive Member
Originally posted by Mike Hildner
Code:
myConnectionString = ConfigurationSettings.AppSettings["database_connection_string"];
This way, your end user can change the config file whenever needed, and you don't need to hard code.
thanks. however, since I need deploy it to a free host which I do not have full control, what I can do? I can upload the mdb file, then the connection string should be what? The original string is:
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C: \Inetpub\wwwroot\MyBooks\MyBooksDB.mdb"
I tried: ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=MyBooksDB.mdb" and put the mdb file in the root directory of \mybooks\, but it does not work.
thanks again.
-
Nov 2nd, 2004, 07:38 PM
#4
Thread Starter
Hyperactive Member
Originally posted by temp_12000
thanks. however, since I need deploy it to a free host which I do not have full control, what I can do? I can upload the mdb file, then the connection string should be what? The original string is:
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C: \Inetpub\wwwroot\MyBooks\MyBooksDB.mdb"
I tried: ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=MyBooksDB.mdb" and put the mdb file in the root directory of \mybooks\, but it does not work.
thanks again.
I just got answer from tech support:
We suppose that your database resides in “Database” subfolder and it name is “TestDB.mdb”.
You’ll have to use Server.MapPath(“Database\TestDB.mdb”) in order to get physical location of database.
So connection string would be:
"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath(“Database\TestDB.mdb”)
And the way to utilize it:
ConnectionString = “"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath(“Database\TestDB.mdb”)
Set DbConnection = Server.CreateObject("ADODB.Connection")
DbConnection.Open ConnectionString
-
Nov 3rd, 2004, 12:05 AM
#5
Brinksters?
-
Nov 20th, 2004, 08:17 AM
#6
New Member
Connection String to MDB database
Did you make it work? If so, how did you do it.
I tried the code in the reply, BUT when executing it the path built is 'C:\WINDOWS\system32\databaseName.MDB'
I 'd like to refer to it as ".\databaseName.mdb"
(meaning: AT CURRENT SUBDIRECTORY find database databaseName.mdb)
Thanks
Imagination is more important than knowledge.
-- Albert Einstein
-
Nov 20th, 2004, 08:55 AM
#7
Use Application.StartUpPath()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|