Create an appsettings.json
file and include your connection string in it.
Connection string issue
Hi,
What kind of file can be inserted, regarding Connection string, into Maui App?
.NET
.NET MAUI
C#
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-16T06:58:16.46+00:00 What kind of file can be inserted, regarding Connection string, into Maui App
What is the expected behavior and how does that differ from the actual behavior?
Which platform do you want to insert this file?
Do you want to read the strings from files in your project?
As Note: Please edit this post to add full details.
-
Peter_1985 2,586 Reputation points
2024-07-16T07:46:14.1133333+00:00 Which kind of file (inside Maui app project) is handling Connection string?
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-17T01:42:15.8766667+00:00 Do you want to read the connection string, then retrieve data from remote SQL Server?
Please do not save your connection string in file, you can write a Web Api with JWT Token and let you App get data from there, you can save the Token in the Secure storage.
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-30T00:48:12.6633333+00:00 How about to run it inside Android? Can you share the details to have it in VS 2022?
Please clarify the following problems:
- What is the scenario you are trying to solve?
- What do you mean by running it inside Android?
- What are you trying to connect to?
- How do you plan to use this string?
As Note: Please edit this post to add full details.
Here is a document about How to write a quality question on Microsoft Q&A | Microsoft Learn
Sign in to comment
2 answers
Sort by: Most helpful
-
Waqar Kabir 1 Reputation point
2024-07-16T17:43:01.1733333+00:00 -
Peter_1985 2,586 Reputation points
2024-07-17T02:23:37.1233333+00:00 To the file like appsettings.json, is it having the similar format like that of Web.config file (in XML)?
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-19T08:34:21.9433333+00:00 appsettings.json cannot be reloaded like Asp.net core webapi in MAUI, you have to put it in the Raw folder, then read it to the Stream.
-
Peter_1985 2,586 Reputation points
2024-07-20T11:18:42.01+00:00 Can you have more details of the way, using an example? Many thanks.
-
Peter_1985 2,586 Reputation points
2024-07-22T07:32:38.1366667+00:00 Is it JavaScript Json configuration file? Do you have one example?
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-22T07:46:48.92+00:00 It is not recommended save your connection string in self-created appsettings.json file. If you insist on to do it, you can find the Resouces/Raw folder, you open the AboutAssets.txt file, will have code about read the file content, you can try to use code to read AboutAssets.txt in your project, then add the
appsettings.json
file -
Peter_1985 2,586 Reputation points
2024-07-22T07:59:06.7+00:00 If there was no connection details within the APP, how can it connect to retrieve the data for its usage?
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-22T09:21:41.9133333+00:00 For example, if you release your application to APK, Others can open your apk file like a compressed file and open your appsettings.json file, see the connection strings. Your DB link will be hacked.
If you still want to connect to DB by strings. You can put it in your code. Then use code obfuscation. When you release your application.
-
Peter_1985 2,586 Reputation points
2024-07-22T09:36:54.0633333+00:00 Yes, it is not good to have Connectionstring.
Do you have more details (further to the current URL above) to embed the linkage in the code?
-
Deleted
This comment has been deleted due to a violation of our Code of Conduct. The comment was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
-
Peter_1985 2,586 Reputation points
2024-07-25T08:31:06.9766667+00:00 Yes. You're right.
-
Peter_1985 2,586 Reputation points
2024-07-25T09:54:09.04+00:00 Yes.
Is Maui executable within both Android and Mac OS, right?
-
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 72,491 Reputation points • Microsoft Vendor
2024-07-29T02:19:18.67+00:00 Is Maui executable within both Android and Mac OS, right?
Yes. By the way, MAUI could run at macOS 11 or higher, using Mac Catalyst.
-
Peter_1985 2,586 Reputation points
2024-07-29T03:08:51.3066667+00:00 How about to run it inside Android? Can you share the details to have it in VS 2022?
Sign in to comment -
-
Bruce (SqlWork.com) 61,811 Reputation points
2024-07-16T19:45:40.2466667+00:00 as its hackable, the connection string should not contain user/password,