Home > Software engineering >  Can I set up a local SQL Server on my Windows machine for my DOTNET Maui App, running on android?
Can I set up a local SQL Server on my Windows machine for my DOTNET Maui App, running on android?

Time:09-10

I am new to DOTNET Maui, and was wondering if it is possible to use the local SQL Server, running locally on my PC, to supply data for my application, running on my Android.

This connection string works when I run the Maui app on my Windows Machine, but I get errors when I run on an emulator, or my android.

//In the data context
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.UseSqlServer("Server=(local);Database=Gym;Trusted_Connection=True;");
}

I could be thinking about this completely wrong, and appreciate all your input, thanks!

CodePudding user response:

When running your SQL server and .NET MAUI app on Windows they are both on the actual same physical machine. That is why local works. Local means that it reaches that exact same machine.

If you then run the .NET MAUI app on an Android emulator, technically it runs on the same machine probably, but your Android emulator is treated as a virtual machine and thus a separate machine. What now happens is that your .NET MAUI apps starts looking for local on the Android emulator so it expects that the SQL server is running on the Android device which is obviously not the case.

On your Windows machine go to your network settings or open a command window and type ipconfig that will give you info on your network. Find an IP address and use that in your .NET MAUI app.

The IP address probably looks like 192.168.x.x or 10.x.x.x where the x stands for other numbers.

More info can also be found here: https://docs.microsoft.com/xamarin/cross-platform/deploy-test/connect-to-local-web-services

  • Related