Skip to content

Commit 2bbe4f3

Browse files
authored
Merge pull request #243 from michaeltlombardi/ticket/master/MODULES-5693-refactor-sql-connection
(MODULES-5693) Replace SQLOLEDB with SQLNCLI11
2 parents 9c899c8 + 2ebc3ab commit 2bbe4f3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/puppet_x/sqlserver/sql_connection.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ def open(config)
2929

3030
def get_connection_string(config)
3131
params = {
32-
'Provider' => 'SQLOLEDB.1',
33-
'Initial Catalog' => config[:database] || 'master',
34-
'Application Name' => 'Puppet',
35-
'Data Source' => '.'
32+
'Provider' => 'SQLNCLI11',
33+
'Initial Catalog' => config[:database] || 'master',
34+
'Application Name' => 'Puppet',
35+
'Data Source' => '.',
36+
'DataTypeComptibility' => 80
3637
}
3738

3839
admin_user = config[:admin_user] || ''

spec/unit/puppet_x/sql_connection_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def stub_connection
1717
context 'command execution' do
1818
before :each do
1919
stub_connection
20-
@connection.stubs(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
20+
@connection.stubs(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@')
2121
end
2222
it 'should not raise an error but populate has_errors with message' do
2323
subject.stubs(:execute).raises(Exception.new("SQL Server\n error has happened"))
@@ -43,7 +43,7 @@ def stub_connection
4343

4444
context 'Use default authentication' do
4545
it 'should defaul to SQL_LOGIN if admin_login_type is not set' do
46-
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
46+
@connection.expects(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@')
4747
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@' })
4848
end
4949
end
@@ -66,11 +66,11 @@ def stub_connection
6666
end
6767

6868
it 'should not add the default instance of MSSQLSERVER to connection string' do
69-
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
69+
@connection.expects(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@')
7070
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@', :instance_name => 'MSSQLSERVER'})
7171
end
7272
it 'should add a non default instance to connection string' do
73-
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.\\LOGGING;User ID=sa;Password=Pupp3t1@')
73+
@connection.expects(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.\\LOGGING;DataTypeComptibility=80;User ID=sa;Password=Pupp3t1@')
7474
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@', :instance_name => 'LOGGING'})
7575
end
7676
end
@@ -93,12 +93,12 @@ def stub_connection
9393
end
9494

9595
it 'should add integrated security to the connection string if admin and password are empty' do
96-
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;Integrated Security=SSPI')
96+
@connection.expects(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;Integrated Security=SSPI')
9797
subject.open_and_run_command('query', {:admin_user => '', :admin_pass => '', :admin_login_type => 'WINDOWS_LOGIN'})
9898
end
9999

100100
it 'should add integrated security to the connection string if admin and password are not defined' do
101-
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;Integrated Security=SSPI')
101+
@connection.expects(:Open).with('Provider=SQLNCLI11;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;Integrated Security=SSPI')
102102
subject.open_and_run_command('query', { :admin_login_type => 'WINDOWS_LOGIN' })
103103
end
104104
end

0 commit comments

Comments
 (0)