Based upon the AppServer my Epicor client is pointed to, it redirects me to the appropriate (Environment/Database) that i should be working with. How can I programmatically find this information to avoid hard coding these values in a connection string inside of a Customization/C#?
For context this would be for a simple Select Query. All data that needs to be updated should/will be done through a business object.
I’m aware of quite a few different solutions to query data from Epicor within a customization, however objectively speaking these are cumbersome to work in comparison with a sql connection inside the customization.
Use and Adapter to pull back data
Use the BOReader
Use a BAQ to query data
The BAQ is the most flexible option, however this requires another object to be included with my solution. I want the flexibility of SQL inside my customization, without the requirement of x amount of BAQs to retreive data. The below code works, but is not an optimal solution. This requires that I hard code my database name and server.
private void MyFunction()
{
SqlConnection conn = new SqlConnection();
//Data Source name is the name of the Server that you are connecting to. Initial Catalog is the name of the actual database. Integrated Security makes it so it uses windows authentication.
conn.ConnectionString = "Data Source=<MyDataSourceName>;" + "Initial Catalog=EpicorLive;" + "Integrated Security=SSPI;";
conn.Open();
try
{
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT Company FROM Erp.Company WHERE Company = 'CO'", conn);
myReader = myCommand.ExecuteReader();
if(myReader.HasRows == true)
{
while(myReader.Read())
{
MessageBox.Show((string)myReader["Company"]);
}
}
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
So as the first sentence states, is there a way to programmitcally obtain this information? Its not available in any of the session variables.
