フィルターのクリア

Can't connect to database when the servername has a backslash in it

27 ビュー (過去 30 日間)
James McBrearty
James McBrearty 2023 年 6 月 27 日
回答済み: James McBrearty 2023 年 7 月 3 日
I am using JDBC to connect to various databases, and as whole everything is working incredibly smooth - However, there is another database located on a server where the servername is something like "PART1\PARTB", when I use this as the servername, the backslash is used as an escape character, and there is a message given as:
"JDBC Driver Error: The TCP/IP connection to the host PART1, port x has failed etc."
This however works for every other database and server, and works on other applications.
The code I use to connect, which I have changed some of the name is:
conn = database('DB1','','','Vendor','Microsoft SQL Server', ...
'Server','PART1\PART2','AuthType','Windows');
Can anyone help me figure out what the issue is here, and what the workaround/fix for this is?
Thanks

採用された回答

James McBrearty
James McBrearty 2023 年 7 月 3 日
So after a bit of work, I managed to get connect to this database:
jdbcDriver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver';
serverName = 'Server';
databaseName = 'DBName';
instanceName = 'Instance';
url = ['jdbc:sqlserver://' serverName ';instanceName=' instanceName ';databaseName=' databaseName ';integratedSecurity=true;'];
conn = database(databaseName,'','',jdbcDriver,url);
So, as can be seen, I just made the URL itself, as the JDBC connection does have an instance property in it, however, MATLAB's database function doesn't so you have to manually do it.
It may be good if @MathWorks Support Team could add this functionality to the existing database code.
Thanks,
James

その他の回答 (1 件)

Jon
Jon 2023 年 6 月 27 日
There may be a much cleaner way to deal with this. I'm not sure of the details of why you get this error. Are you on a windows machine? If so you can map your network drive and then just use the mapped drive location without the slashes
  1 件のコメント
James McBrearty
James McBrearty 2023 年 6 月 28 日
So it is an internal server, but the permissions involved may not allow me to map it as a drive, as it is not a network drive. I have tried this on 2023a, and have had the same issues.
I'm assuming it will be a Java issue, due to backslash being an escape character.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by