Connection to a database

조회 수: 1 (최근 30일)
Fragkiskos Nikolakis
Fragkiskos Nikolakis 2017년 1월 12일
답변: Piyush Kumar 2024년 9월 26일
I have a script in which data from an ORACLE database are called. The problem is that the connection isn't always succesfull. After 3-4 attempts the connection is succesfull. Do you know why does ths happen? Thanks
  댓글 수: 3
the cyclist
the cyclist 2017년 1월 12일
Are you certain that it is not something outside of MATLAB that is failing? It would be unusual for the code itself to be a source of intermittent failure.
Fragkiskos Nikolakis
Fragkiskos Nikolakis 2017년 1월 12일
편집: the cyclist 2017년 1월 12일
the query for the database is
function[Vessel_Data]=stpQuery(selected_fields1)
% Set preferences with setdbprefs.
s.DataReturnFormat = 'dataset';
s.ErrorHandling = 'store';
s.NullNumberRead = 'NaN';
s.NullNumberWrite = 'NaN';
s.NullStringRead = 'null';
s.NullStringWrite = 'null';
s.JDBCDataSourceFile = '';
s.UseRegistryForSources = 'yes';
s.TempDirForRegistryOutput = 'Path';
s.DefaultRowPreFetch = '10000';
setdbprefs(s)
% Make connection to database. Note that the password has been omitted.
% Using ODBC driver.
conn = database('Base','usr','pswd');
% Read data from database.
e = exec(conn,selected_fields1);
e = fetch(e);
close(e)
% Assign data to output variable.
Vessel_Data = e.Data;
% Close database connection.
close(conn)

댓글을 달려면 로그인하십시오.

답변 (1개)

Piyush Kumar
Piyush Kumar 2024년 9월 26일
The intermittent connection issue to a database may be due to several problems -
  • Network issues: Check the network connectivity of the server where the database is hosted and the server from where you are trying to connect.
  • Database load: If the database server is under heavy load, it might not be able to handle all connection requests immediately.
  • Timeout settings: Check the connection timeout-related settings of the database.
Refer to the following resources to get more details -

카테고리

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