15,904,652 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by dolce_sweet (Top 2 by date)
dolce_sweet
18-Sep-23 4:58am
View
I can understand your concerns.
The connection string is stored in appsettings.json.
"ConnectionStrings": {
"Default": "Data Source=192.168.99.101\\SQLEXPRESS;Initial Catalog=DemoDatabase;Integrated Security=True;TrustServerCertificate=True;Encrypt=False"
},
First once without user and password. But I have already tried that too.
My sample tests:
- "Data Source=.\\SQLEXPRESS; Initial Catalog=DemoDatabase; User Id=SimpleUser; Password=SimpleUserPassword; TrustServerCertificate=True; Encrypt=False"
- "Data Source=.\\SQLEXPRESS; Initial Catalog=DemoDatabase; Integrated Security=True"
- "Data Source=DNS-Name\\SQLEXPRESS; Initial Catalog=DemoDatabase; Integrated Security=True; TrustServerCertificate=True; Encrypt=False"
- "Data Source=DNS-Name\\SQLEXPRESS; Initial Catalog=DemoDatabase; User Id=SimpleUser; Password=SimpleUserPassword; TrustServerCertificate=True; Encrypt=False"
- "Data Source=DNS-Name\\SQLEXPRESS; Initial Catalog=DemoDatabase; Integrated Security=True"
- "Data Source=DNS-Name\\SQLEXPRESS; Initial Catalog=DemoDatabase; User Id=sa; Password=sapassword; TrustServerCertificate=True; Encrypt=False"
- "Data Source=IP-Address\\SQLEXPRESS; Initial Catalog=DemoDatabase; User Id=sa; Password=sapassword; TrustServerCertificate=True; Encrypt=False"
- "Server=.\\SQLEXPRESS; Database=DemoDatabase; User Id=SimpleUser; Password=SimpleUserPassword; TrustServerCertificate=True; Encrypt=False"
The json is read into the main MauiProgram.cs class and then the DbContextFactory is registered from it.
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(MauiProgram)).Assembly;
string strAppConfigStreamName = string.Empty;
strAppConfigStreamName = "MauiGoesEntity.appsettings.json";
var stream = assembly.GetManifestResourceStream(strAppConfigStreamName);
var config = new ConfigurationBuilder()
.AddJsonStream(stream)
.Build();
builder.Configuration.AddConfiguration(config);
var appSettings = System.Text.Json.JsonSerializer.Deserialize<appsettings>(assembly.GetManifestResourceStream(strAppConfigStreamName));
var connectionString = appSettings.ConnectionStrings.Default;
builder.Services.AddMauiBlazorWebView();
builder.Services.AddScoped<mauigoesentity.entity.data.orders.iauftraguebersichtservice, mauigoesentity.entity.data.orders.auftraguebersichtservice="">();
builder.Services.AddScoped<mauigoesentity.entity.data.idatabasecontext, mauigoesentity.entity.data.databasecontext="">();
builder.Services.AddDbContextFactory<mauigoesentity.entity.data.databasecontext>((DbContextOptionsBuilder options) =>
options.UseSqlServer(connectionString));
dolce_sweet
18-Sep-23 3:08am
View
Thank you very much for your help. I have checked all your suggestions and that was not the problem.
I have a link for you which will allow you to download my sample project (https://mycsharp.de/forum/posts/3840302). Search for "MauiGoesEntity.zip". This is from me.
Feel free to criticize the architecture of the sample project, but I don't spend too much time on the architecture of a sample project. It should simply represent in a lean way what my problem is. And in this example, it's about not being able to connect a database to the local SQL Server after a roll-out.
I am already happy to get a hint where I made a mistake / error in thinking, so I can fix it as soon as possible and close my knowledge gap.
Since I have not been working with MAUI for long, I ask for your indulgence.