Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

andreff

Erro Conexão Mysql

Recommended Posts

Pessoal,

 

Fiz uma classe de conexão com banco. mais não consigo tirar erro: o conector do mysql ja configurei de acordo com meu banco e acontece este erro

 

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Data.Odbc;

 

 

namespace DAO

{

public class ConexaoDAO

{

string strCon = "DSN=teste;uid=root;pwd=123456;";

 

public int execSQL(string sSQL)

{

OdbcConnection oConn = null;

OdbcCommand oCmd = null;

int regAffect = 0;

try

{

oConn = new OdbcConnection(strCon);

oCmd = new OdbcCommand(sSQL, oConn);

oConn.Open();

regAffect = oCmd.ExecuteNonQuery();

if (regAffect == 0)

{

throw new Exception("O registro não pode ser incluído");

}

return regAffect;

}

catch (Exception err)

{

return -1;

}

finally

{

oConn.Dispose();

oCmd.Dispose();

}

}

 

public DataSet getDataSet(String command, string table)

{

OdbcDataAdapter dataAdapter;

 

OdbcConnection cn = new OdbcConnection();

 

cn.ConnectionString = strCon;

 

 

cn.Open();

 

 

dataAdapter = new OdbcDataAdapter(command, cn);

 

DataSet ds = new DataSet();

 

dataAdapter.Fill(ds, table);

return ds;

}

}

 

 

 

 

ERROR [HY000] [MySQL][MyODBC 5.00.11][MySQL] 1046 No database selected

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.Data.Odbc.OdbcException: ERROR [HY000] [MySQL][MyODBC 5.00.11][MySQL] 1046 No database selected

 

Source Error:

 

Line 60: DataSet ds = new DataSet();

Line 61:

Line 62: .

Line 63: dataAdapter.Fill(ds);

Line 64:

Compartilhar este post


Link para o post
Compartilhar em outros sites

e se tu definir um banco na string de conexão?

 

tipo: string strCon = "DSN=teste;uid=root;pwd=123456;Database=myDataBase;";

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.