Home > Enterprise >  Connect to local database on other computers
Connect to local database on other computers

Time:06-05

How can I use my LocalDB on other computers?

SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v.11.0;AttachDbFilename=[DataDirectory]\Database1.mdf;Integrated Security=True");

I tried this but it doesn't work because I get this error:

Local Database Runtime error occurred. Cannot create an automatic instance

Does someone know how to fix this, or what I can do instead?

I don't want to use SQLServer because I am making a program for an offline computer.

CodePudding user response:

The fact that your app is for an offline computer is irrelevant. If you're attaching an MDF file on demand then that will only work with a SQL Server instance installed on the local machine anyway.

As suggested elsewhere, LocalDB is intended for development use only. Your users should be installing SQL Server Express and you can specify that in the connection string. If you're going to use a SQL Server data file, i.e. an MDF file, then you need a SQL Server instance to attach it to. If you don't want to have to have a SQL Server instance installed then don't use a SQL Server data file in the first place.

CodePudding user response:

LocalDb is sql server and is only intended for development purposes. It isn't something you would use for distributing an application. SQL Express is an option for you, but may be overkill for what you need. You might look into SQLite as you might find it easier to embed and distribute with your application. Of course, the right answer depends on your actual requirements, etc.

  • Related