没有启动数据库管理器命令发出错误 [英] No start database manager command was issued error
问题描述
我有一个DB2 EX preSSS在我的机器,我能够从数据库中使用命令窗口(以下两条命令后)查询:
设置DB2INSTANCE = db2inst1的
DB2 Connect的以TIMS用户
现在,当我尝试连接到从C#控制台应用程序的数据库,我收到以下错误有不同的连接字符串。
尝试1
字符串的connectionString = @供应商= IBMDADB2;数据库= TIMS;主机名=本地主机; CurrentSchema = db2inst1的;;
SQL1032N没有启动数据库管理器发出命令。 SQLSTATE = 57019
尝试2
字符串的connectionString = @供应商= IBMDADB2;数据库= TIMS; CurrentSchema = db2inst1的;;
SQL1031N数据库目录不能指定的文件系统中找到。 SQLSTATE = 58031
我应该是这种情况下正确的连接字符串?
code
字符串的connectionString = @供应商= IBMDADB2;数据库= TIMS;主机名=本地主机; CurrentSchema = db2inst1的;;
OleDbConnection的MyConnection的=新的OleDbConnection();
myConnection.ConnectionString =的connectionString;
myConnection.Open();
我的DB2 insatnce名称为db2inst1的,当我使用DB2命令窗口,这是工作的罚款。
现在我做以下设置,这是工作的罚款了。 : - )
- 创建一个端口在C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ etc \ services文件(db2c_db2inst1 50010 / TCP)
- 将TCP / IP服务名称(= db2c_db2inst1)的实例。验证使用DB2 GET DBM CFG命令
- 更新了环境变量DB2INSTANCE的值db2inst1的
- 重新启动计算机
- 入门实例
的ConnectionString
提供程序= IBMDADB2;数据库= TIMS;主机名=本地主机;协议= TCPIP; PORT = 50010; UID = myUserID; PWD = MYPASSWORD;
code
字符串查询字符串=SELECT * FROM DBATABC;
尝试
{
使用(OleDbConnection的连接=新的OleDbConnection(的connectionString))
{
OleDbCommand的命令=新的OleDbCommand(查询字符串,连接);
connection.Open();
OleDbDataReader读者= Command.ExecuteReader却();
如果(reader.HasRows)
{
而(reader.Read())
{
如果(!reader.IsDBNull(0))
{
串公司code = reader.GetString(0)的ToString();
}
}
}
reader.Close();
}
}
注:尝试创建DSN的ODBC和使用示例SSIS包ODBC连接。这将解决OLEDB连接问题,还可以帮助(这是常见的两种)
I have a DB2 expresss in my machine and I am able to query from the database using command window (after following two commands):
set DB2INSTANCE=db2inst1
db2 connect to tims user
Now, when I try to connect to the database from a C# console application, I am getting following errors with different connection strings.
Attempt 1
string connectionString = @"Provider = IBMDADB2; Database = TIMS; Hostname = localhost; CurrentSchema=db2inst1; ";
SQL1032N No start database manager command was issued. SQLSTATE=57019
Attempt 2
string connectionString = @"Provider = IBMDADB2; Database = TIMS; CurrentSchema=db2inst1; ";
SQL1031N The database directory cannot be found on the indicated file system. SQLSTATE=58031
What should be the correct connection string for this scenario?
CODE
string connectionString = @"Provider = IBMDADB2; Database = TIMS; Hostname = localhost; CurrentSchema=db2inst1; ";
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = connectionString;
myConnection.Open();
My DB2 insatnce name is "db2inst1" and it was working fine when I used DB2 command window.
Now I made following settings and it is working fine now. :-)
- Created a port in the C:\Windows\System32\drivers\etc\services file (db2c_db2inst1 50010/tcp)
- Set the "TCP/IP Service Name" ( = db2c_db2inst1") for the instance. Verified using "db2 get dbm cfg" command
- Updated the environment variable DB2INSTANCE with the value "db2inst1"
- Restarted the machine
- Started the instance
ConnectionString
"Provider = IBMDADB2; Database = TIMS; Hostname = localhost; Protocol = TCPIP; Port = 50010; Uid = myUserID; Pwd = myPassword";
CODE
string queryString = "SELECT * FROM DBATABC";
try
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(queryString, connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
if (!reader.IsDBNull(0))
{
string companyCode = reader.GetString(0).ToString();
}
}
}
reader.Close();
}
}
Note: Try to create DSN for ODBC and use ODBC connection in a sample SSIS package. This will help in resolving OLEDB connection issues also (that are common to both)
这篇关于没有启动数据库管理器命令发出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!