error CS0029: Cannot implicitly convert type 'System.Data.Odbc.OdbcConnection' to...

Hi there.

I can do it connect with DB MySQL from .NET

The error is:

error CS0029: Cannot implicitly convert type ‘System.Data.Odbc.OdbcConnection’ to ‘string’

web.config


<?xml version="1.0"?>
<configuration>

  <appSettings/>
  <ConnectionStrings>
    <add
    name="ConnMySQL"
    myConnectionString="Driver={MySQL ODBC 5.1 Driver};
    Server=localhost;
    Database=com714;uid=root;pwd=XXX;option=3;"
    providerName="System.Data.Odbc" />;
  </ConnectionStrings>

  <location path="Register.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>
    
  </configuration>

default4.aspx:


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.Odbc" %>

<!DOCTYPE html 
   PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

public void Page_Load (Object sender, EventArgs e)
{

    OdbcConnection myConnectionString = new OdbcConnection();
    myConnectionString.ConnectionString = myConnectionString;
    myConnectionString.Open();
    
    myConnectionString.Close();
   

 }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
</body>
</html>

Can u help me?


 myConnectionString.ConnectionString = ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString;

Thanks Sir.

I fixed with:

web.config


<?xml version="1.0"?>
<configuration>

		<connectionStrings>
			<add name="ConnMySQL" connectionString="Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=com714;uid=root;pwd=xxx;option=3;" providerName="System.Data.Odbc"/>
		  <add name="ApplicationServices" connectionString="data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
		</connectionStrings>

  <system.web>
			<compilation debug="true" targetFramework="4.0">
				<assemblies>
					<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
			<authentication mode="Forms">
				<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
			</authentication>
			<membership>
				<providers>
					<clear/>
					<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
				</providers>
			</membership>
			<profile>
				<providers>
					<clear/>
					<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
				</providers>
			</profile>
			<roleManager enabled="false">
				<providers>
					<clear/>
					<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
					<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
				</providers>
			</roleManager>
		</system.web>
		<system.webServer>
			<modules runAllManagedModulesForAllRequests="true"/>
		</system.webServer>

</configuration>

Default4.aspx


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Configuration" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

public void Page_Load (Object sender, EventArgs e)
{
    OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
    myConnectionString.Open();

    myConnectionString.Close();     
 }  

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
</body>
</html>