0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MAUI Tips - SQL Serverとの接続エラー回避(取扱い注意)

Posted at

概要

LAN上にある.NET MAUI アプリ(Android端末で実行)と
SQL Serverを接続させようとした際に発生したエラーを
とりあえず回避する方法の備忘録。

環境

◾️Android端末(API 30)
Visual Studio for MAC
.NET MAUI
.NET 7
Microsoft.Data.SqlClient(Ver 5.1.1)

◾️サーバー
SQL Server 2022

発生したエラー

※スマホアプリでデータベースを直接見に行くのは
 いかがなものかという話は置いといて・・・。

SQL Serverに接続すると、以下のような例外が発生。

A connection was successfully established with the server, 
but then an error occurred during the pre-login handshake. 
(provider: TCP Provider, error: 35 - An internal exception was caught)

同じコードでAzure SQL Databaseには接続できていたので、
何かしらサーバー側の設定なんだと思って調べていたけど、
よくわからず・・・。

解決策

githubのissueを読んでいたら、今回の環境(ローカルネットワーク内で閉じた接続)であれば
適用できる解決策が記載されていました。

https://github.com/dotnet/SqlClient/issues/1656#issuecomment-1355500465

上記のリンク先のコードをそのまま実装したところ、エラーを回避できます。
※このリンク先にも書いてありますが、この解決策はセキュリティ上問題があります。

サーバー証明書がない場合に、Android側のセキュリティによってエラーとなるようですね。
自己証明書でも同様のエラーになるかは未確認です。

今回の環境やケースは特殊なので、あくまで参考までに・・・ということで。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?