Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Well im using the code

C#
public static MySqlConnection GetConnection(string server, string user, string password, string db)
{
    string str = "Server='" + server + "';user='" + user + "';password='" + password + "';database='" + db + "';";
    MySqlConnection con = new MySqlConnection(str);
    con.Open();
    isConnected = true;
}



And i cant seem to figure out why its giving me the error :Not all code paths return a value, i was wondering if someone could help me out with this
Posted

You need to return an object of type MySqlConnection. In this case that would be con.
 
Share this answer
 
Comments
raju melveetilpurayil 19-Oct-10 9:29am    
you are right :)
That method must return a MySqlConnection object.
Probably
return con;

just before the closing curly bracket will do the trick.
:rolleyes:
 
Share this answer
 
v2
the problem is, that you are not returning a MySqlConnection. What you could do is:

C#
public static MySqlConnection m_con;

public static MySqlConnection GetConnection(string server, string user, string password, string db)
{
    string str = "Server='" + server + "';user='" + user + "';password='" + password + "';database='" + db + "';";
    m_con = new MySqlConnection(str);
    con.Open();
    isConnected = true;
    return m_con;
}
 
Share this answer
 
Comments
Tunacha 19-Oct-10 8:19am    
How would i add conection error catching to that code thats what im overall trying to do with the isConnected
CPallini 19-Oct-10 8:21am    
what is the purpose of introducing 'm_con'?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900