this is my common app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="BO"
connectionString="Data Source=MyServer;Initial Catalog=BO;User ID=WebUser;Password=xxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
And I’m working on a library, class.cs. Here’s the part of the code where I get the error.
public static SqlConnection getNewConnection()
{
string conection = ConfigurationManager.ConnectionStrings["BO"].ConnectionString.ToString();
conn = new SqlConnection(conection);
return conn;
}
Error 1 The name ‘conn’ does not exist in the current context
Any idea? I have not copied any other file that’s being referenced to the same file. (some error I’ve read is common when it comes to “does not exist in the current context”)
Where is conn declared ? Did you already declare it in an outer scope ? If not, declare it and you will be good.
Change this line
to
You can alternatively use implicit declaration using the
varkeyword. It is available fromC# 3.0onwards.The compiler will infer the type of the variable from the expression on the right side of the initialization statement
from msdn