How To Change Database Connection String?
Hi, i'm using BarTender 9.4 SR3 with .net c# 2010. I made a label with a query from my local SQL Sever database (developer enviroment), and i have a winforms applications who load this label and print what i want.
From the BarTender Editor everything works fine, but my custom application have to connect to another database (production enviroment). Anyone can tellme how to change the label's connection string from .net?
This is part of my code:
private void ImprimirEtiquetaRecepcion(int Cliente, int CodigoRecepcion)
{
// Initialize a new TaskManager object
string SQL = "SELECT Cliente, IdRecepcion, FechaRecepcion " +
"FROM dbo.Recepcion " +
"WHERE Cliente=10 AND IdRecepcion=1500";
try
{
// Start TaskEngines
Engine barEngine = new Engine(true);
// Specify a label format
LabelFormatDocument btFormat = barEngine.Documents.Open(@"c:\myLabel.btw");
// Create a cached OLE DB database connection and set the SQL statement
OLEDB oleDB = new OLEDB("Database");
//***** Put here the new connection string Server=MyServer;Database=Mydatabase;User ID=user;Password=pwd;
oleDB.SQLStatement = SQL;
// Set this database on the LabelFormat. The new file name will be
// transferred to the label format document when the Task is run
btFormat.DatabaseConnections.SetDatabaseConnection(oleDB);
// Create and submit a new print task
btFormat.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
From the BarTender Editor everything works fine, but my custom application have to connect to another database (production enviroment). Anyone can tellme how to change the label's connection string from .net?
This is part of my code:
private void ImprimirEtiquetaRecepcion(int Cliente, int CodigoRecepcion)
{
// Initialize a new TaskManager object
string SQL = "SELECT Cliente, IdRecepcion, FechaRecepcion " +
"FROM dbo.Recepcion " +
"WHERE Cliente=10 AND IdRecepcion=1500";
try
{
// Start TaskEngines
Engine barEngine = new Engine(true);
// Specify a label format
LabelFormatDocument btFormat = barEngine.Documents.Open(@"c:\myLabel.btw");
// Create a cached OLE DB database connection and set the SQL statement
OLEDB oleDB = new OLEDB("Database");
//***** Put here the new connection string Server=MyServer;Database=Mydatabase;User ID=user;Password=pwd;
oleDB.SQLStatement = SQL;
// Set this database on the LabelFormat. The new file name will be
// transferred to the label format document when the Task is run
btFormat.DatabaseConnections.SetDatabaseConnection(oleDB);
// Create and submit a new print task
btFormat.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
0
-
Gene Henson
★ BarTender Hero ★
Hello,
The SDK has a Database Namespace (Seagull.BarTender.Print.Database) that you can use to change the SQL statement for OLE DB and ODBC data sources.
Here is an example:
[code]
// Initialize a new TaskManager object
TaskManager btTaskManager = new TaskManager();
string SQL = "SELECT `Calories` FROM `NutritionInformation`";
try
{
// Start TaskEngines
btTaskManager.Start(5);
// Specify a label format
LabelFormat btFormat = new LabelFormat(@"c:\NutritionLabel.btw");
// Create a cached OLE DB database connection and set the SQL statement
OLEDB oleDB = new OLEDB("MyDatabase");
oleDB.SQLStatement = SQL;
// Set this database on the LabelFormat. The new file name will be
// transferred to the label format document when the Task is run
btFormat.DatabaseConnections.SetDatabaseConnection(oleDB);
// Create and submit a new print task
PrintLabelFormatTask printTask = new PrintLabelFormatTask(btFormat);
btTaskManager.TaskQueue.QueueTask(printTask);
}
finally
{
// Stop the task engine
btTaskManager.Stop(5000, true);
}
[/code]
You can find more information in the BarTender Help by searching for "SQL" and “Database Namespace”
Hope that helps!0 -
Legacy Poster
★ BarTender Hero ★
Hello Gene,
On this example "MyDatabase" refers to label formtat's database connection's name, but i need to set the OLEDB connection to another database on another server.
Can I declare another name which refers to a new database connection, something like that?:
string AnotherDatabase = "Server=ProdServer;Database=ProdDatabase";
OLEDB oleDB = new OLEDB("AnotherDatabase");
oledb.UserID = "Admin";
oledb.SetPassword("newpassword");
oleDB.SQLStatement = "SELECT `Calories` FROM `NutritionInformation`";
Or i need to create this new connection on the .btw databases?
Thanks a lot for your help0 -
Gopen Dholakiya
★ BarTender Hero ★
Hello,
I'm facing the same issue, database on another server how can I configure it with .net sdk ?
I'm using SQL server database, I'm looking for solution since long time but I didn't get expected solution even I've tried to contact bartender technical support team...
Thanks.
0
Please sign in to leave a comment.
Comments
3 comments