• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

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
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
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.
 

Reza

Member
Joined
Oct 22, 2017
Messages
5
Programming Experience
1-3
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.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
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.
 

Reza

Member
Joined
Oct 22, 2017
Messages
5
Programming Experience
1-3
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
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,166
Location
Sydney, Australia
Programming Experience
10+
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.
 
Top Bottom