views:

22

answers:

1

I know it can be simple to access a mysql or sql database on godaddy.. i have done it before, but now i have lost the code. Now the code that should be working just comes up with a security exception.

So how do i create a asp or aspx file on my godaddy free hosting account that will connect to a database i have already set up (mysql,sql or ms access) and simple add a value that was passed in the query string?

looking for the simplest solution here i don't care if its "asp.net,asp,aspx,html" or whatever below is what i have so far which does not work.

on my root/web.config

<!-- Web.Config Configuration File -->

    <configuration>
        <system.web>
            <customErrors mode="Off"/>
    <compilation debug="true"/>
        </system.web>
    </configuration>

in my root/aspsqltest.aspx

<%
dim Username
dim Password
Username = Request.Form("txtUsername")    
Password = Request.Form("txtPassword")

Response.Write("try")
Dim connectionString, conn, rs
Response.Write("thing 1")
connectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=syncnote2.db.6666015.hostedresource.com; DATABASE=syncnote2; UID=root; PASSWORD=sensored;"
Response.Write("thing 2")
conn = Server.CreateObject("ADODB.Connection")
Response.Write("thing 3")
conn.Open(connectionString)
Response.Write("thing 4")
rs = conn.Execute("SELECT * FROM userlogin where username='"& Username &"'")   
Response.Write("sucsess")
%>

and the error is:

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.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 


Line 10: connectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=syncnote2.db.6666015.hostedresource.com; DATABASE=syncnote2; UID=root; PASSWORD=sensored;"
Line 11: Response.Write("thing 2")
Line 12: conn = Server.CreateObject("ADODB.Connection")
Line 13: Response.Write("thing 3")
Line 14: conn.Open(connectionString)

Source File: D:\Hosting\6666015\html\aspsqltest.aspx    Line: 12 

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Web.HttpServerUtility.CreateObject(String progID) +45
   ASP.aspsqltest_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in D:\Hosting\6666015\html\aspsqltest.aspx:12
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.aspsqltest_aspx.ProcessRequest(HttpContext context) +37
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

thank you very much for your help, my only real goal here is to be able to store a value in a database on my godaddy free hosting account.. it really should not be so hard.

A: 

You're mixing your technologies. You have an ASP.NET page (.aspx), yet you have classic ASP code in there. conn = Server.CreateObject("ADODB.Connection")

Suggest pick one, and code for reading your MySQL database:

  • classic ASP - create a new file - test.asp, and post this code into it. Really it's the code that you posted above.

  • ASP.NET - modify this code in a new file test.aspx

That host will be able handle either. You may need to tweak something on your host control panel.

p.campbell
Going the classic ASP route just results in a generic 500 error. the ASP.net method over complicates the entire thing this should be simple. Do i need to have a DSN installed? would ms access be easier? what about sql server instead of mysql?
nathan
@nathan. Likely the 500 err is because the website isn't configured to process ASP files. Perhaps there's a setting in the host's control panel? I'd suggest SQL Server being easier in terms of finding good sample code.
p.campbell
@p.campbell i can not find any setting in the control panel to enable .asp files or even anything that looks similer. Maybe you know a free and easy way to do what i am trying to do at another host?
nathan
The ASP.NET route ended up working.
nathan