Results 1 to 7 of 7

Thread: [solved] a question about deployment of database in ASP.net

  1. #1

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

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



  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    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.

  3. #3

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411
    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.



  4. #4

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411
    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



  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Brinksters?

  6. #6
    New Member
    Join Date
    Nov 2004
    Posts
    2

    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

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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
  •  



Click Here to Expand Forum to Full Width