cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble connecting mySQL db in Plesk to web app (a form)

Hi All,

 

A friend who is a developer built a web application (a collection of three webpages with authentication, a database connection and some validation functions) for me. I built a local MySQL database, we connected the two and we tested it locally with IIS. We worked out the UI / design flaws, then I got a new domain and opened a Plesk hosting account with GoDaddy. I put all of the files up, migrated the MySQL database to the server using phpMyAdmin.

 

**EDIT** Should have mentioned, it's a .NET app, not using PHP, WordPress or anything like that.

 

I can access the database and see the data via phpMyAdmin. I've modified the connection string in the local app in Visual Studio to point to the hosted database and I can see the data. The files between the local app and the hosted ones are the same. The web.config page is the same, with the same connection string. With all of that said, when I start the app in Visual Studio, I open the dropdown for user and the usernames populate. When I go to the application hosted on the domain and I do the same thing, there are no values in the dropdown. I'm super confused.

 

I'm not sure what the needed context is for someone to help me, but I'm running out of ideas and I want to soft-launch the site as soon as I can.

 

Here's the web.config file contents (with credentials and server addresses replaced with placeholders). If you need more info, please let me know, but I'd really appreciate some help!!!

 

Thanks,

Mike

 

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation targetFramework="4.5.2" defaultLanguage="c#" />
    <httpRuntime targetFramework="4.5.2" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
    <customErrors mode="Off" />
    <authentication mode="None" />
  </system.web>
  <!-- <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>-->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <defaultDocument>
      <files>
        <clear />
        <add value="Login.aspx" />
        <add value="index.aspx" />
        <add value="index.html" />
        <add value="Default.html" />
        <add value="default.asp" />
        <add value="index.htm" />
        <add value="default.aspx" />
        <add value="lisstart.htm" />
      </files>
    </defaultDocument>
  </system.webServer>
  <connectionStrings>
    <add name="TaskEntry" connectionString="server=[server ip address]; database=[db name]; UId=[user ID]; pwd=[password]" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

9 REPLIES 9

Hi @mbaughan,

Welcome to our forums. Sounds like your hosting account is working as it should but the issue you are having is more regarding the platform you are using. Hopefully, one of our community members can chime in and assist you. 

KayJay - GoDaddy | Community Moderator
24/7 support available at x.co/247support

Hi @charminglygeeky, I figured that it was a configuration issue as well, as the app and database work as expected when the application is local and the database is either hosted or local, but not when the app and database are hosted. I don't know if I've got to request some special access or something from GoDaddy or if I have to change something in my config. I just don't know where to start.

Hi @charminglygeeky, I'm very confused. I worked with my developer over the weekend to see if we could figure it out and we couldn't. We tried a number of permutations of the connection string yet the .NET app, when hosted on GoDaddy, would never connect to the hosted database. We really think that either we're missing a key element from the connection string (some property or attribute that the GoDaddy servers require in order for a hosted app to connect to a hosted database) or some other bit of configuration on the server that doesn't have to do with the connection string, specifically.

 

Can you please provide an example of a working connection string (with the credentials/IP/data source values stripped out, of course) for a .NET app to connect to a MySQL server via Plesk?

That's to say I don't know if any of the options referenced here are required, and if so, which ones and which values??

Hey @mbaughan,

 

By chance, have you reviewed Connecting to a MySQL Database Using ASP.NET? We have a basic walk through there with a general script example that should help out. 

 

You could also try this test script which is good for testing connections to a database:

<%@ Import Namespace="System.Data.ODBC" %>
<html>
    <head>
        <title>.NET MySQL Test Script</title>
    <head>
    <body>
        <%
            'Replace server, username, password and database_name with the correct information
            Dim MyConnection As OdbcConnection = New OdbcConnection
            MyConnection.ConnectionString ="DRIVER={MySQL ODBC 3.51 Driver};SERVER=server;DATABASE=database_name;USER=username;PASSWORD=password;OPTION=0;"
            MyConnection.Open()
            Response.write("Connection Open!")
         %>
    </body>
</html>

Hope this helps. Let us know how it goes. 

 

CG - GoDaddy | Community Moderator
24/7 support available at x.co/247support

Thanks for the suggestion, @CG. I have the 5.1 ODBC driver installed - I'm assuming I'll have to change the string from {MySQL ODBC 3.51} to {MySQL ODBC 5.1}?

 

I'm also really new to this. How would I apply/run that script? I put it up in the file system and when I opened the page it just showed me the text.

Hey @mbaughan,

 

The extra script example is just a test file you can setup to confirm connections to a database server are functioning. Generally you'd use this code in a another file like "mysqltest.aspx" for example.

 

As for the ODBC driver version; not that I'm aware. Our hosting team sometimes use this exact same script to verify connection responses to the server are functioning and the only values they generally update are the: server, username, password and database_name with the correct information for the database in question.

If you want to implement this example into your own pages where you're having trouble connecting the database, I'd recommend reviewing this with your site developer.  Unfortunately, database site scripting is not my strongest skill set and I'd hate to recommend changes that might cause more harm than good. 

 

Hopefully, what I've given so far is enough to help you and your developer reach a solution for your site. 

 

CG - GoDaddy | Community Moderator
24/7 support available at x.co/247support

Hi @CG,

 

The script, modified with the parameters for my database, fails with the following exception.

 

Line 10: MyConnection.Open()

 

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.Odbc.OdbcPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

 

Also, the script is using an ODBC connection to try and connect to the database. The connection string we're using with the local app which points to the hosted database and successfully retrieves data is using ASP.NET.

 

<add name="TaskEntry" connectionString="server=[server IP address]; port=3306; database=[db_name]; User ID=[user id value]; password=[password value]" providerName="MySql.Data.MySqlClient" />

FYI, I was on a few support calls last week and we discovered that it was something on the server backend that is causing the connection to fail. What that is has yet to be determined, but I've created a service ticket which is being escalated to the Hosting Admin team.

My application was receiving a HTTP500 error (Internal Server error), detectable by going to the console in F12 developer tools and refreshing a page that queries the database. This indicated that application could not connect.

The support person on my most recent call was very helpful (Joe S.). He did some investigating and had me run a script (below) which tested to see if a page on the server could connect to the database via ODBC. Although I wanted to use the .NET/MySQL connector, this would work in a pinch. He put the script as a file "MySQL.asp" in HTTPDOCS and asked me to run it (by going to [mydomain]/MySQL.asp). I did, entered my db credentials and it would not connect.

I'll keep this post up-to-date with developments as others might have this issue and need some reference.

Here's that script btw.

<html>
	<body>
		<%
		if request.form("dbhost") <> "" then
			Set objConn = CreateObject("ADODB.Connection")
			objConn.open = ("Driver={MySQL ODBC 3.51 Driver}; Server=" & request.form("dbhost") & "; Database=" & request.form("dbname") & "; UID=" & request.form("dbuser") & "; PWD=" & request.form("dbpass") & "; Option=3")
			objConn.close
			set objConn = nothing
			Response.Write("The connection to " & request.form("dbhost") & " was successful.")
		else %>
			<form method="post">
				<table>
					<tr>
						<td> Database Host: </td>
						<td><input type="text" name="dbhost"></td>
					</tr>
					<tr>
						<td> Database Name: </td>
						<td><input type="text" name="dbname"></td>
					</tr>
					<tr>
						<td> Database User: </td>
						<td><input type="text" name="dbuser"></td>
					</tr>
					<tr>
						<td> Database Password: </td>
						<td><input type="password" name="dbpass"></td>
					</tr>
					<tr>
						<td></td>
						<td><input type="submit" value="submit"></td>
					</tr>
				</table>
			<%
		end if
		%>
	</body>
</html>