Is it possible to make connection string dynamically change whenever a C# application is installed in another computer?

maprisoka

I just deployed the project I created and when I shared the setup file and ran the application in another computer the database did not work. I think I know what the problem is, but I do not have the slightest idea on how to fix it because I am new to SQL.

I think the problem is the connection string:

        SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=X:\Documents\SMS.mdf;Integrated Security=True;Connect Timeout=30");

Can someone tell me how fix it please? the application is a project for my course. Any help will do, thanks.

vivek nuna

Based on your question title, yes We can get different connection strings. All you need to do is define the connection string in some config file like App.Config or Web.Config or AppSettings.Json (Depending on the kind of application and target .net framework version).

and then read the respective configuration based on the environment or machine.

Refer these https://learn.microsoft.com/en-us/dotnet/api/system.configuration.configuration?view=dotnet-plat-ext-7.0

https://learn.microsoft.com/en-us/visualstudio/ide/how-to-add-app-config-file?view=vs-2022

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

C# Remake connection string on another computer

Is it possible to dynamically change MS - SimpleMembership database connection?

Make dynamically HangFire connection string .NetCore

Is it possible to change the keyboard layout when no operating system is installed on the computer?

How to copy an installed application to another computer that lacks the build tools?

C# Sql connection string, trying to connect to local db from another computer

Is it possible to change an installed application from ALL USERS to specific user?

Meteor: Possible to check if application has already open instance on another computer?

Laravel Change Connection Dynamically

Dynamically change connection string in Asp.Net Core

How to change Entity Framework EDMX connection string dynamically

Is it possible in the body of an email to make a link that will launch my Delphi app installed in the local computer?

Is it possible to make the design of a C# application with CSS

How do I make my published web app that is installed on my IIS be accessed by another computer

Having to restart tomcat whenever you make a change

building connection string dynamically

How to create an odbc string connection in an excel spreadsheet to make it portable instead of setting up an odbc connection on every computer?

C# change custom connection string at runtime

When a variable change in a C# console application, the connection automatically change

Is it possible to make the if statement change one img to another slowly?

How to make JavaScript to change string if it matches another string?

Retrieve minsdk of another installed application

Spring Boot - Change connection dynamically

Change the Database Connection Dynamically in Laravel

is it possible to make push notifications to all devices which had installed my application without Firebase Cloud Messaging (FCM)?

Moving installed instance of windows to another computer?

How to connect to another computer(windows installed) with SSH?

Installed Programs/Computer Info for Web Application

JavaFX get the version of a specific application installed in a computer