%% Remove Driver-Specific Connection Option
% Edit an existing JDBC data source for a Microsoft® SQL Server® database. Set an additional JDBC driver-specific option, and test the database connection. Then, remove the additional JDBC driver-specific option, and test and save the data source.
%
% Retrieve the existing SQL Server data source SQLServerDataSource.

datasource = "SQLServerDataSource";
opts = databaseConnectionOptions(datasource)

% opts is an SQLConnectionOptions object with these properties:
% DataSourceName — Name of the data source
% Vendor — Database vendor name
% JDBCDriverLocation — Full path of the JDBC driver file
% DatabaseName — Name of the database
% Server — Name of the database server
% PortNumber — Port number
% AuthenticationType — Authentication type
%
% Add a JDBC driver-specific connection option by using a name-value pair argument. The option specifies a timeout value for establishing the database connection. opts contains a new property for the additional JDBC connection option.

opts = setoptions(opts,'loginTimeout',"20")

%
% Test the database connection with a blank user name and password. The testConnection function returns the logical 1, which indicates the database connection is successful.

username = "";
password = "";
status = testConnection(opts,username,password)

%
% Remove the JDBC driver-specific option for specifying a timeout value. The opts object no longer contains the loginTimeout property.

opts = rmoptions(opts,'loginTimeout')

%
% Test the database connection again.

username = "";
password = "";
status = testConnection(opts,username,password)

%
% Save the data source.

saveAsDataSource(opts)

% Copyright 2020 The MathWorks, Inc.