Shared Hosting - Medium Trust - my DB doesn't work

Last post 05-16-2008 3:40 AM by Bruce L. 8 replies.

Sort Posts:

  • Shared Hosting - Medium Trust - my DB doesn't work

    05-08-2008, 11:14 PM
    • Loading...
    • dave_smith
    • Joined on 10-09-2007, 3:47 PM
    • Posts 9

     I have a simple ACCESS DB and am using a gridview to show the contents. Everything looks fine when run locally using my local ASP .NET dev server.

    The shared hosting I use is Netfirms.com  and they use a medium trust.   

    How do I set my Visual Web developer 2008 express website to use Medium trust for this website.

    I can't find anything in  Website -> ASP.NET configuration .

     

    I found the MSDN  web page at: http://msdn.microsoft.com/en-us/library/ms998326.aspx#paght000017_step3

    "The main constraints placed on medium trust Web applications are:

    1. OleDbPermission is not available. This means you cannot use the ADO.NET managed OLE DB data provider to access databases. However, you can use the managed SQL Server provider to access SQL Server databases.


     Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file."

     I'm getting the error message-->

    Security Exception

    Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.




    "Overview

    By default, ASP.NET version 1.1 and version 2.0 Web applications and Web services run with Full trust. When an application runs with Full trust, code access security places no restrictions on the resources and operations it can access, and resource access is based solely on operating system security and Windows access control lists (ACLs).

    To protect your ASP.NET application, you can use code access security to restrict the resources the application can access and the privileged operations it can perform. You do this by configuring the <trust> element in either the machine-level Web.config file or the application's Web.config file and setting it to one of the predefined trust levels, as shown here."

    ___________

    NETFIRMS.COM, the webhost SAYS 

    Medium Trust Summary is available directly from Microsoft's website: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000020.asp 
     
    The main constraints placed on medium trust Web applications are:

    1. OleDbPermission is not available. This means you cannot use the ADO.NET managed OLE DB data provider to access databases. However, you can use the managed SQL Server provider to access SQL Server databases.

    2. EventLogPermission is not available. This means you cannot access the Windows event log.
    3. ReflectionPermission is not available. This means you cannot use reflection.
    4. RegistryPermission is not available. This means you cannot access
    the registry
    5. WebPermission is restricted. This means your application can only communicate with an address or range of addresses that you define in the <trust> element.
    6. FileIOPermission is restricted. This means you can only access files in your application's virtual directory hierarchy. Your application is granted Read, Write, Append, and PathDiscovery
    permissions for your application's virtual directory hierarchy.
    7. You are also prevented from calling unmanaged code or from using Enterprise Services.

    NOTE: For additional ASP.NET support and resources we recommend the following web sites:

    ______________________

     

    I tried adding

                <trust level="Medium" originUrl="~/App_Data/SID_Dealers_Access2002-3.mdb" />

     referring to an ACCESS 2003 DB

    right after the <system.web> in the root directory web.config file

    WHAT IS THE CORRECT SYNTAX AND LOCATION  OF THE TRUST ELEMENT?

    I assume that if I get the trust element entered connrectly in the root directory web.config file, this DB will run on the shared hosting. 

    Dave 

     

     


     

     

  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-09-2008, 2:48 PM
    Answer
    • Loading...
    • Bruce L
    • Joined on 02-08-2007, 1:53 PM
    • Posts 747

    <system.web><trust level="[Full|High|Medium|Low|Minimal]" /></system.web>

    I highly doubt that your hosting provider will allow you to override the trust level.  I am actually a little surprise that they didn't modify the medium trust template to allow OleDB.   If they don't have a custom template for medium trust, you will need to elevate to Full Trust for OleDB to work.

    I think your best bet is to ask them how to get MS Access to work on their server.  Still can't get it to work.. consider switching to another provider.

    Bruce
    DiscountASP.NET: Developer Ready ASP.NET Web Hosting
    - Microsoft Gold Certified Partner
    - Voted 2008, 2007, 2006 & 2005 Best ASP.NET Web Hosting by asp.netPRO Magazine
  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-09-2008, 6:36 PM
    • Loading...
    • dave_smith
    • Joined on 10-09-2007, 3:47 PM
    • Posts 9

     Netfirms.com is using a medium trust setting.

     

    I guest that the website uses "Full on my local development server and therefore needed this medium statement to be added to work on the web hosting server according to the web hosting company. 

    They stated that we can use the <trust level="Medium"/> in the web.config file which I interpret will tell the application to use medium instead of full....but that doesn't work.

    I put that trust level element in the root directory web.config and even in other folders like the App_Code and App_Data but it still didn't work.

    I am not happy that Netfirms.com and 1and1.com haven't installed Net 3.0 or now 3.5 and are way behind the times.

    Netfirms website as previously posted above does  support what I want to do but I must be missing something in the implementation.

    Thanks for the reply.

    Dave 

     

     

  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-09-2008, 8:28 PM
    • Loading...
    • dave_smith
    • Joined on 10-09-2007, 3:47 PM
    • Posts 9

     Netfirms.com states that you have to use an odbc connection to use Access on their medium trust ASP .net 2.0

    The techie didn't know much.

    It just referred me to connectionstrings.com which states:

    ODBC

    Standard Security


    Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;

     How do I implement this in either a aspx webpage under the AccessDatasouirce controls or do I have to implement it in a similar fashion as one would if using ASP .NET 1.1

     

    I'm lost now

    Dave 

     

     

  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-09-2008, 9:15 PM
    • Loading...
    • Bruce L
    • Joined on 02-08-2007, 1:53 PM
    • Posts 747

    Wow.. you have to use ODBC.. that's quite lame.

    Anyway, you can still change the connection string to the one they provided in your web.config.

    Bruce
    DiscountASP.NET: Developer Ready ASP.NET Web Hosting
    - Microsoft Gold Certified Partner
    - Voted 2008, 2007, 2006 & 2005 Best ASP.NET Web Hosting by asp.netPRO Magazine
  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-11-2008, 8:44 PM
    • Loading...
    • dave_smith
    • Joined on 10-09-2007, 3:47 PM
    • Posts 9

     What do you mean by "Anyway, you can still change the connection string to the one they provided in your web.config."

     

    They didn't provide one. 

  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    05-12-2008, 3:04 AM
    Answer

    Personally, I would find another web host.  That's a rediculous constraint they have placed on you, and suggests they have no idea what they are doing.  But that may not be an option for you. ODBC with Access is quite horrid, but you may be stuck with it.  Basically, you will have to ditch all the AccessDataSource controls in your app, and change them to SqlDataSource controls, then set a connection string using ODBC in your web.config and reference that in your SqlDataSource controls.

    Someone already provided a sample ODBC connection string for you further up the thread.
    [EDIT] Oh, that was you Wink

     

    Regards Mike
    [Microsoft MVP ASP/ASP.NET]
  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    22 hours, 31 minutes ago
    • Loading...
    • dave_smith
    • Joined on 10-09-2007, 3:47 PM
    • Posts 9

     I did make a SqlDataSource control but must have gotten something wrong.

     

    The ODBC connection string didn't work. It refers to a local machine and  the word "Driver"   caused an error.

    I've been through so many variations o n this that my head is spinning .

     Thanks for looking at this and replying. Perhaps all I need is the proper connection string in the web.config file.

    I tried it but must have failed to make it correctly. 

    I then started to just do it in MSSQL. The account has 1 MS Sql database included .  I open up the control panel and found 2 databases, one with 179 tables from various customers that weren't related to the web hosting account.  I then created the table in the database after spending hours trying to figure out why the database didn't work and found that the name , which uses a number for the database in myLIttleAdmin, the database administration tool, was different than that in the control panel at Netfirms.com  I then got it to work by deleting it in the Netfirms.com control panel and starting over and it then matched the database name number. Now it says it's importing the csv file ( one simple table) into the database but no records appear after it completes.  They technical help has been unresponsive for the last week, just asking nonsense questions.  I tried changing delimiters and with and without quotes and nothing worked.

    WHAT A NIGHTMARE THIS HAS BEEN

     

    Does the connection string above for the ODBC need a dsn parameter?   What should it be.

    Dave Smith 

     

     

  • Re: Shared Hosting - Medium Trust - my DB doesn't work

    20 hours, 19 minutes ago
    • Loading...
    • Bruce L
    • Joined on 02-08-2007, 1:53 PM
    • Posts 747

    What exactly is your connection string?  Can you post it?

    In addition, do you know the path to your website root (or where the database is locate?)

    Bruce
    DiscountASP.NET: Developer Ready ASP.NET Web Hosting
    - Microsoft Gold Certified Partner
    - Voted 2008, 2007, 2006 & 2005 Best ASP.NET Web Hosting by asp.netPRO Magazine
Page 1 of 1 (9 items)