win form application does not run on another machine

Reza

Member
Joined
Oct 22, 2017
Messages
5
Programming Experience
1-3
hi
i have a win form application written c# in Visual Studio 2017.
it's a simple client registration form with Linq to SQL that uses a .mdf database file stored in the \bin\debug folder.
while running the application on my own machine there is no problem, and it runs fine. but when i create a setup for it using publish command of the VS and installing it on another machine ( for instance the virtual machine installed on this laptop), it shows an error message that it could not connect to the database.
this is the error message
forum
 
Did you actually read that error message? It tells you pretty much all you need to know. The data file is useless on its own without an appropriate SQL Server instance to be attached to.
 
Did you actually read that error message? It tells you pretty much all you need to know. The data file is useless on its own without an appropriate SQL Server instance to be attached to.

i have MS SQL server 2012 Express LocalDB installed on this machine. but it does not work. that was the reason to post the problem.
forum
 
Then that is information that you should have provided in the first place. We only know what you tell us so you have to tell us everything that is relevant. If the error message says that the LocalDB instance doesn't exist then the inference is obvious.

What version of SQL Server did you develop against? I wonder whether it's a version issue, as SQL Server databases have a compatibility level and higher-level databases can't attach to lower-level instances. I don't know whether you'd get a different error message in that case or not, but you can test that to find out.
 
Then that is information that you should have provided in the first place. We only know what you tell us so you have to tell us everything that is relevant. If the error message says that the LocalDB instance doesn't exist then the inference is obvious.

What version of SQL Server did you develop against? I wonder whether it's a version issue, as SQL Server databases have a compatibility level and higher-level databases can't attach to lower-level instances. I don't know whether you'd get a different error message in that case or not, but you can test that to find out.

my code in written in C# using MS Visual Studio 2017
i have created this mdf database using visual studio itself (from server explorer i added a Data connection and selected "MS SQL server Database file" and saved that database file in \bin\Debug folder where the exe file exist. than i have made a table in it. i added a "Linq to sql class" added the table to that class. then in form load event i added the folowing code to show the data in a "data grid view":

private LinqClassDataContext Context = new LinqClassDataContext();
var AllData = from User in Context.Users select User;
this.dataGridView1.DataSource = AllData;

to answer to the question about the version of sql server i have some versions installed on my own machine that i use for programing that are all but the compact version is installed by visual studio.
Capture.JPG
also on the target machine i have installed sql server 2012 express localdb
 
The version of LocalDB on your machine appears to be 2016 so it may well be a version issue. If you create a database in SQL Server Management Studio 2016 against a SQL Server 2016 instance then, unless you specify otherwise, it will not be compatible with an instance of any earlier version. It seems quite likely that the situation could be similar for LocalDB. I don't know that for a fact but I'd suggest that you try installing the 2016 version of LocalDB on that machine and see if it works then. I suspect that it will.

You might also check the connection string being used because there might have been a change in format at some point between those version. That's a stab in the dark but it's worth checking out.
 

Latest posts

Back
Top Bottom