Please help!!! >> MSSQLconn Error using MSSQLconn (line 58) Not enough input arguments.

1 次查看(过去 30 天)
function [Out, Settings] = MSSQLconn(employee_attendance, userpassmethod, varargin)
%------------------------------------------------------------------------------------- % CHECK part %-------------------------------------------------------------------------------------
% 1. # of inputs narginchk(1,5)
% 2. dbname if ~ischar(employee_attendance); error('MSSQLconn:strFmt', 'dbname must be char'); end
% 3. userpassmethod if nargin == 1 isempty(userpassmethod); method = '-default'; elseif iscell(userpassmethod) method = '-cell'; else method = userpassmethod; end winAuth = 'false'; user = ''; pass = ''; % Default values switch method case '-default' % Use default values case '-cell' if numel(userpassmethod) == 2 % [1] IF 2 cells user = userpassmethod{1}; pass = userpassmethod{2}; if ~isempty(user) && ischar(user) && isempty(pass) % [2] IF pass empty while isempty(pass) pass = inputdlg('Supply password: ', 'Empty not admitted',1); pass = pass{:}; end elseif ~isempty(pass) && ischar(pass) && isempty(user) % [2] IF user empty while isempty(user) user = inputdlg('Supply username: ', 'Empty not admitted',1); user = user{:}; end end else error('MSSQLconn:upmFmt', 'userpassmethod wrong format'); end case '-win' if any(str2double(struct2cell(ver('database'))) < 3.5) ; error('MSSQLconn:wauMth', 'Feature unavailable for Database Toolbox release older than 3.5 (R2008b)') else winAuth = 'true'; end case '-manual' while isempty(user) isempty(pass) userpass = inputdlg({'Supply username: '; 'Supply password: '}, 'ENTER BOTH',1,{'',''},'on'); user = userpass{1}; pass = userpass{2}; end end
% 4. Oldver IDXo = strcmp('-old',varargin); if any(IDXo) drv = 'com.microsoft.jdbc.sqlserver.SQLServerDriver'; else drv = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'; end
% 5. Port IDXn = cellfun(@isnumeric,varargin); if nnz(IDXn) == 1 && mod(varargin{IDXn},1) == 0 port = num2str(varargin{IDXn}); elseif nnz(IDXn) > 1 error('MSSQLconn:prtFmt', 'Only one numeric integer port is accepted') else port = '1433'; end
% 6. Server IDXs = cellfun(@ischar, varargin) & ~IDXo; if any(IDXs); server = varargin{IDXs}; else server = 'localhost'; end
%------------------------------------------------------------------------------------- % ENGINE part %-------------------------------------------------------------------------------------
% Url concatenation URL = ['jdbc:sqlserver://' server ':' port ';database=' employee_attendance ';integratedSecurity=' winAuth ';'];
% Set connection timeout (s) logintimeout(drv, 10);
% Connect Out = database('', user, pass, drv, URL);
% Settings if nargout == 2 Settings = cell2struct({employee_attendance; user; drv; server; port; ~strcmp(winAuth,';');Out.Message},... {'databaseName'; 'user'; 'driver'; 'server'; 'port'; 'windowsAuthentication'; 'errorMsg'}); end
% [1] IF connected if isconnection(Out) % Initialize Status Status = '.'; % [2] IF readonly if isreadonly(Out); Status = ' in "READONLY" mode.'; end % [2] % Display connection status sprintf('Connected%s', Status) else % [1] IF not connected % Display error error('MSSQLconn:conInv',Out.Message) end % [1]
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by