C#做BarTender二次开发连接SQL-Server数据库报错

兵工厂三剑客 兵工厂三剑客 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
因为现在在做BarTender的二次开发,想实现服务器数据库的套打。我是用的BarTender10.1的Seagull.BarTender.SystemDatabase 里面的关于访问SQL-Server数据库的一些类来弄。
相关代码如下:

SystemDatabaseConnection connection = new SystemDatabaseConnection();
connection.Method = SystemDatabaseConnectionMethod.Manual;
connection.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;
connection.ServerName = @"DELL-PC";
connection.DatabaseName = "生产部自动派号数据库";
connection.UserName = "sa";
connection.Password = "sql";
connection.Connect();
string sqlcommand = "select MAC号 from " + dbs.ToString() + " where MAC号 between '" + FirstMAC + "' and '" + LastMAC + "'";
OLEDB oledb = new OLEDB("MyDataBase");
oledb.SQLStatement = sqlcommand;
LabelFormatDocument format = mybtEngine.Documents.Open(@txt_FormatPath.Text.Trim());
format.DatabaseConnections.SetDatabaseConnection(oledb);
format.Print();
format.Close(SaveOptions.DoNotSaveChanges);
mybtEngine.Stop();

这个时候会报如下的错误:

Seagull.BarTender.SystemDatabase.SystemDatabaseConnectionException”类型的未经处理的异常在
Seagull.BarTender.Print.dll 中发生
其他信息: 连接数据库时遇到问题。\n\n详细资料:\n\n找不到存储过程 'dbo.sp_GetDBVersion'。


如果我把connection.ServerName = @"DELL-PC";改成 connection.ServerName = @"DELL-PC\生产部自动派号数据库";
则会报下面的错误:

“Seagull.BarTender.SystemDatabase.SystemDatabaseConnectionException”类型的未经处理的异常在
Seagull.BarTender.Print.dll 中发生
其他信息: 连接数据库时遇到问题。\n\n详细资料:\n\n在与 SQL Server 建立连接时出现与网络相关的或特定于

实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。

(provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)

数据库是装在局域网内的一台电脑上,不在本机上。我用C#的System.Data.SqlClient都能正常操作数据库,但是用BarTender的就出现上面的错误。


下面是SystemDatabaseConnection的成员变量:
Name Description
Authentication Gets or sets the authentication method to use when connecting to the system database.
ConnectionString Gets or sets the string used to open a SQL Server database.
DatabaseName Gets or sets the database name of the BarTender System Database. A typical name is "BarTender".
Method Gets or sets the connection method to use when connecting to the system database.
Password Gets or sets the password to use when connecting to the system database.
ServerName Gets or sets the server name where the system database is located on the network.
UserName Gets or sets the user name to use when connecting to the system database.
Version Returns the system database version identifier. Read-only.

下面是BarTender帮助文档的相关使用代码:
In order to use the System Database SDK, you must establish a connection with a BarTender System Database in order to access information saved by applications in the BarTender Suite. A connection to the BarTender System Database is made using the SystemDatabaseConnection class. 

The following code demonstrates how to automatically connect to the BarTender System Database using the settings specified in the BarTender System Database Setup dialog.

In C#:

try

{

SystemDatabaseConnection connection = new SystemDatabaseConnection();

connection.Connect();

}

catch (SystemDatabaseConnectionException ex)

{

// Handle can't connect or database not configured exceptions

}

To manually connect to a BarTender System Database, you must specify the following connection parameters:

The location of the SQL server database, using the ServerName property;

The name of the BarTender System Database, using the DatabaseName property;

The type of user authentication (Windows or SQL), using the Authentication property.

(Only when using SQL Server Authentication) Login credentials, using the UserName and Password properties.

The following code demonstrates how to manually configure a connection to a BarTender System Database using SQL server authentication.

In C#:

try

{

SystemDatabaseConnection connection = new SystemDatabaseConnection();

connection.Method = SystemDatabaseConnectionMethod.Manual;

connection.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;

connection.ServerName = @"MyServer\BarTender";

connection.DatabaseName = "BarTender";

connection.UserName = "MyUserName";

connection.Password = "MyPassword123";

// Connect to the BarTender System Database

connection.Connect();

}

catch (SystemDatabaseConnectionException ex)

{

// Handle can't connect or database not configured exceptions

}




请教下大家,我的问题该如何解决。
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
兵工厂三剑客
C# 111,129 成员 642,539 内容