Skip to content

Commit ea0e1b1

Browse files
committed
[MSSQL] Fix loading of layers in browser and dialog.
Add ODBC connection pooling
1 parent d34b759 commit ea0e1b1

File tree

3 files changed

+15
-40
lines changed

3 files changed

+15
-40
lines changed

src/providers/mssql/qgsmssqldataitems.cpp

+1-18
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,7 @@ QVector<QgsDataItem*> QgsMssqlConnectionItem::createChildren()
109109
return children;
110110
}
111111

112-
QString connectionName;
113-
if ( mService.isEmpty() )
114-
{
115-
if ( mHost.isEmpty() )
116-
{
117-
children.append( new QgsErrorItem( this, "QgsMssqlProvider host name not specified", mPath + "/error" ) );
118-
return children;
119-
}
120-
121-
if ( mDatabase.isEmpty() )
122-
{
123-
children.append( new QgsErrorItem( this, "QgsMssqlProvider database name not specified", mPath + "/error" ) );
124-
return children;
125-
}
126-
connectionName = mHost + "." + mDatabase;
127-
}
128-
else
129-
connectionName = mService;
112+
QString connectionName = db.connectionName();
130113

131114
QgsMssqlGeomColumnTypeThread *columnTypeThread = 0;
132115

src/providers/mssql/qgsmssqlprovider.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ QgsMssqlProvider::QgsMssqlProvider( QString uri )
8787
if ( !OpenDatabase( mDatabase ) )
8888
{
8989
setLastError( mDatabase.lastError( ).text( ) );
90+
QgsDebugMsg( mLastError );
9091
mValid = false;
9192
return;
9293
}
@@ -225,7 +226,10 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString service, QString host, QStri
225226
connectionName = service;
226227

227228
if ( !QSqlDatabase::contains( connectionName ) )
229+
{
228230
db = QSqlDatabase::addDatabase( "QODBC", connectionName );
231+
db.setConnectOptions("SQL_ATTR_CONNECTION_POOLING=SQL_CP_ONE_PER_HENV");
232+
}
229233
else
230234
db = QSqlDatabase::database( connectionName );
231235

@@ -263,6 +267,7 @@ QSqlDatabase QgsMssqlProvider::GetDatabase( QString service, QString host, QStri
263267
db.setPassword( password );
264268

265269
db.setDatabaseName( connectionString );
270+
QgsDebugMsg( connectionString );
266271
return db;
267272
}
268273

src/providers/mssql/qgsmssqlsourceselect.cpp

+9-22
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()
497497

498498
mConnInfo = "dbname='" + database + "'";
499499
if ( !host.isEmpty() )
500-
mConnInfo += " host=" + host + "'";
500+
mConnInfo += " host='" + host + "'";
501501
if ( !username.isEmpty() )
502502
mConnInfo += " user='" + username + "'";
503503
if ( !password.isEmpty() )
@@ -516,27 +516,7 @@ void QgsMssqlSourceSelect::on_btnConnect_clicked()
516516
return;
517517
}
518518

519-
QString connectionName;
520-
if ( service.isEmpty() )
521-
{
522-
if ( host.isEmpty() )
523-
{
524-
QMessageBox::warning( this,
525-
tr( "MSSQL Provider" ), "QgsMssqlProvider host name not specified" );
526-
return;
527-
}
528-
529-
if ( database.isEmpty() )
530-
{
531-
QMessageBox::warning( this,
532-
tr( "MSSQL Provider" ), "QgsMssqlProvider database name not specified" );
533-
return;
534-
}
535-
connectionName = host + "." + database;
536-
}
537-
else
538-
connectionName = service;
539-
519+
QString connectionName = db.connectionName();
540520

541521
// Read supported layers from database
542522
QApplication::setOverrideCursor( Qt::WaitCursor );
@@ -784,6 +764,13 @@ void QgsMssqlGeomColumnTypeThread::run()
784764

785765
// issue the sql query
786766
QSqlDatabase db = QSqlDatabase::database( mConnectionName );
767+
if ( !QgsMssqlProvider::OpenDatabase( db ) )
768+
{
769+
QString msg = db.lastError().text();
770+
QgsDebugMsg( msg );
771+
continue;
772+
}
773+
787774
QSqlQuery q = QSqlQuery( db );
788775
q.setForwardOnly( true );
789776
if ( !q.exec( query ) )

0 commit comments

Comments
 (0)