I connected MSSQL (on windows) via odbc on linux redhat 64bit.
Below is odbc and freetds configuration files.
freetds.conf:
[FreeTDS]
host=172.21.32.20
port=1433
tds version=7.2
client charset = GB2312
odbcinst.ini:
[TDS]
Description = TDS
Driver = /usr/local/lib/libtdsodbc.so
Trace = Yes
TraceFile=/tmp/odbcinst.log
UsageCount = 1
odbc.ini:
[SQLSERVER]
Driver = TDS
Description = sql server dsn
Trace = NO
Server = 172.21.32.20
Database = Live
Port = 1433
TDS_Version = 7.2
TraceFile=/tmp/sqlserver.log
Snippets:
QString f3ErpDsn = QString::fromLocal8Bit("Driver={SQLSERVER};server=172.21.32.20;database=Live;uid=inp;pwd=inp;");
QSqlDatabase f3ErpDb= QSqlDatabase::addDatabase("QODBC");
f3ErpDb.setDatabaseName(f3ErpDsn);
// f3ErpDb.setDatabaseName("SQLSERVER");
f3ErpDb.setUserName("inp");
f3ErpDb.setPassword("inp");
QString sqlCmdStr = "select * from dbo.Table_Drilling_Data01 where status=1";
if ( ! f3ErpDb.open() )
{
qDebug() << f3ErpDb.lastError().text();
return 1;
}
QSqlTableModel model;
model.setTable("dbo.Table_Drilling_Data01");
model.setFilter("status=3");
model.select();
qDebug() << model.lastError().text();
Error messages:
f3ErpDb.setDatabaseName(f3ErpDsn);
If setDatabaseName is f3ErpDsn error message is:
"QODBC3: Unable to connect", "[unixODBC][Driver Manager]Data source name not found, and no default driver specified")
I had defined SQLSERVER in odbc.ini. Why it can not find it?
But if I changed f3ErpDb.setDatabaseName("SQLSERVER");, error message is:
"[FreeTDS][SQL Server]The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 (""): Data type 0x00 is unknown. QODBC3: Unable to execute statement"
It makes me confounded, could anybody help me?
I'm not sure what QSqlDatabase is. But it seems that you have improper SQL connection string.
Try something like this:
UID=inp;PWD=inp;DSN=SQLSERVER;database=Live;SERVER=AMIN\SQLEXPRESS;charset=UTF-8
DSN=SQLSERVER because SQLSERVER is the only DSN which defined in your odbc.ini
SERVER=AMIN\SQLEXPRESS - try Windows name of SQL Server, not host's IP address (I'm not sure that IP is not allowed here, but Windows name is 100% working)
I had the same problem and I solve it when I changed TDS protocol to 8.0, it was at 7.0 before. I've used freetds, unixodbc, via Qt to connect to MSSQL database.
Related
I have a problem running the command upsert in MongoDB when I try to connect 3 shards.
If I connect only one shard, I don't have problems.
The code I'm using is:
ConnectionString cs("mongodb://host:pass#server1:27017,server2:27017,server3:27017", ConnectionString::ConnectionType::SYNC);
DBClientBase *conn = cs.connect( mongo_erro );
BSONObjBuilder bojUpsert;
bojUpsert.append("teste","1234567890");
bojUpsert.append("valor",123);
conn->update("xxx.xxx", Query("{teste:\"1234567890\"}") , bojUpsert.obj() , mongo::UpdateOptions::UpdateOption_Upsert);
And the error I receive is:
**terminate called after throwing an instance of 'mongo::UserException'
what(): SyncClusterConnection::update upsert query needs _id**
I'm using Linux Mint, QT 4.8.6 + libmongo-client-dev 0.1.7-1
There are zillions of these questions I know, but none of them were similar to my issue, so I figured I'd ask. I have a server set up that validates clients that connect to it by receiving username/password combinations and checking them using a SQL query. I wrote the system, and it worked perfectly fine during the first couple of requests.
http://puu.sh/d9mss/384b4df9f0.png
However, I found that if I wait about 5 minutes and then try to connect, this happens.
http://puu.sh/d9mx7/192cbb2cfc.png
This is the code that I am running to perform that task.
bool CNetDatabase::AuthUser(std::string username, const unsigned char* passwordhash)
{
RoughSanitizeString(username); //this doesn't do anything
/* Turn password hash into string */
std::ostringstream password;
password.fill('0');
password << std::hex;
for (int i = 0; i < 20; i++)
{
password << std::setw(2) << (unsigned int)passwordhash[i];
}
/* Make request */
MYSQL_RES* result = nullptr;
if (mysql_query(sql_con, tools::string::format(
"SELECT COUNT(`index`) FROM `Users` WHERE `username` = '%s' AND `password` = '%s'",
username.c_str(), password.str().c_str()).c_str()))
{
fprintf(
stderr,
"ERROR: mysql_query failed: %s [%d]\n",
mysql_error(sql_con), mysql_errno(sql_con));
return false;
}
/* Get and return result */
result = mysql_store_result(sql_con);
MYSQL_ROW row = mysql_fetch_row(result);
mysql_free_result(result);
return row[0][0] == '1' ? true : false;
}
Any ideas on what could be going wrong?
Check MySQL manual. There are session timeouts on both client and server side.
Anyway it is a good practice to expect that connection to external resources may become unavailable and try to reconnect (for instance database server could be physically rebooted). You can try to set reconnect flag when creating connection to enable automatic reconnects but those might not always work depending on your environment.
Upon further investigation, I think it's safe to conclude that it is my host's problem, not my code. I registered an account with a site that offered the ability to make free MySQL databases, and my server has been throwing SQL queries at it without issue all night. For posterity, if you are using your website's SQL server and are hosting with Hostgator, they might be causing the issue.
I'm running a django-celery application on Ubuntu-12.04.
When I run a celery task from my web interface, I get the following error, taken form postgresql-9.3 logfile (maximum level of log):
2013-11-12 13:57:01 GMT tss_usr 8113 LOG: could not receive data from client: Connection reset by peer
tss_usr is the postgresql user of the django application database and (in this example) 8113 is the pid of the process who killed the connection, I guess.
Have you got any idea on why this happens or at least how to debug this issue?
To make things work again I need to restart postgresql which is extremely uncomfortable.
I know this is an older post, but I just found it because I had the same error today in my postgres logs. I narrowed it down to a PDO select statement. I'm using Zend Framework 1.10.3 on Ubuntu Precise.
The following pdo statement generated an error if $opinion is a long text string. The column opinion is type Text in my postgres table. The query succeeds if $opinion is under a certain number of characters. 1000 characters works fine. 2000 characters fails with "could not receive data from client: Connection reset by peer".
$select = $this->db->select()
->from( 'datauserstopics' )
->where("opinion = ?",trim($opinion))
->where("datatopicsid = ?",trim($tid))
->where("datausersid= ?",$datausersid);
$stmt = $this->db->query($select);
I circumvented the problem by using:
->where("substr(opinion,1,100) = ?",trim(substr($opinion,1,100)))
This is not a perfect solution, but for my purposes, the select statement using substr() suffices.
Note that I have no problem inserting long strings into the same table/column. The disconnect problem only appears for me on the PDO select with relatively long text strings.
I'm getting it in 2017 with 9.4, I have no text fields, don't know what a PDO is. My select statement is about 50 bytes long, I'm trying to fetch an int4 and a double precision. I suspect the error message can mean multiple things.
I've since found https://dba.stackexchange.com/questions/142350/postgres-could-not-receive-data-from-client-connection-reset-by-peer which indicates it could be a problem with the client configuration. My client is libpg and PQconnectdb() is giving me a CONNECTION_OK return. It works at least partly.
For me, restarting the hypervisor where both the Postgres and the application using it helped. I've seen stack traces in dmesg before, though.
I have a Python/Django app that will require database load balancing at some point in the near future. In the meantime I'm trying to learn to implement pgpool on a local virtual machine setup.
I have 4 Ubuntu 12.04 VMs:
192.168.1.80 <- pool, pgppool2 installed and accessible
192.168.1.81 <- db1 master
192.168.1.82 <- db2 slave
192.168.1.83 <- db3 slave
I have pgpool-II version 3.1.1 and my database servers are running
PostgreSQL 9.1.
I have my app's db connection pointed to 192.168.1.80:9999 and it works fine.
The problem is when I use Apache ab to throw some load at it, none of
SELECT queries appear to be balanced. All the load goes to my db1
master. Also, quite concerning is the load on the pool server itself,
it is really high compared to db1, maybe an average of 8-10 times
higher. Meanwhile my db2 and db3 servers have a load of nearly zero,
they appear to only be replicating from db1, which isn't very load
intensive for my tests with ab.
ab -n 300 -c 4 -C 'sessionid=80a5fd3b6bb59051515e734326735f80' http://192.168.1.17:8000/contacts/
That drives the load on my pool server up to about 2.3. Load on db1
is about 0.4 and load on db2 and db3 is nearly zero.
Can someone take a look at my config and see if what I'm doing wrong?
backend_hostname0 = '192.168.1.81'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/var/lib/postgresql/9.1/main'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = '192.168.1.82'
backend_port1 = 5433
backend_weight1 = 1
backend_data_directory1 = '/var/lib/postgresql/9.1/main'
backend_flag1 = 'ALLOW_TO_FAILOVER'
backend_hostname2 = '192.168.1.83'
backend_port2 = 5434
backend_weight2 = 1
backend_data_directory2 = '/var/lib/postgresql/9.1/main'
backend_flag2 = 'ALLOW_TO_FAILOVER'
load_balance_mode = on
My entire config is here:
http://pastebin.com/raw.php?i=wzBc0aSp
I needed
replication_mode = off
master_slave_mode = on
Thanks to Tatsuo Ishii:
http://www.pgpool.net/pipermail/pgpool-general/2013-January/001309.html
I'm writing my first database application following a sample program the teacher given, but neither the sample, nor my own program can't connect to the database. (The JDBC sample program can, so the server should be OK).
I have these vars in the class declaration:
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
Here's the constructor of my database handler class, that's where the connection should be made:
DBModule::DBModule(string server, string database)
{
this->server = server; //"localhost" is loaded into it
this->database = database; //"test" is loaded into it, of course it exists on the server
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
command = "DRIVER={MySQL ODBC 3.51 Driver};SERVER="+this->server+";DATABASE="+this->database+";";
//command looks like this now:
//"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;"
ret = SQLDriverConnect(dbc, NULL, (SQLWCHAR *)command.c_str(), SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);
if (!SQL_SUCCEEDED(ret)) {
err += CONNECT_DATABASE*DATABASE_UNREACHABLE;
good = false;
return;
} else {
good = true;
}
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
command = sysToStd(DBINIT);
SQLPrepare(stmt, (SQLWCHAR *)command.c_str(), SQL_NTS);
ret = SQLExecute(stmt);
}
The ret at SQLDriverConnect gets a -1 value.
I'm using the latest XAMPP as server with all the default settings (so i'm "root" and there is no password). I've tried adding UID=root to the connection string, but it did the same.
Thanks for any help.
You probably do not have MySQL ODBC drivers installed. JDBC works because you need not "install" them: they are some .jar files that can come with Java application. If you will use ODBC then install MySQL ODBC drivers, configure connection in ODBC Manager as System DSN, then from ODBC manager check if it connects to database (most ODBC drivers I know have "test connection" button).
When such test shows you "connected" or similar, then you can test if your application connects. Your connect sting looks like:
DRIVER={MySQL ODBC 3.51 Driver};SERVER=...;DATABASE....
so according to: http://www.connectionstrings.com/mysql#p30 it looks you are trying to use MySQL Connector/ODBC 3.51
Maybe database is not listening on dafult port?