Skip to main content

Search

Search

How To Change Database Connection String?

Comments

3 comments

  • Avatar
    Gene Henson
    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
  • Avatar
    Legacy Poster
    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 help
    0
  • Avatar
    Gopen Dholakiya

    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.