I am using a SQL local database attached in the project when I copy the whole project on another pc and run bin\Debug myapp.exe its run but give me an error connecting to the database
but when I install visual studio on the pc and run the project from vs its works fine.
and when I delete its go back to the same error
I want to make it run without the visual studio, please
that is my connection string
string domain = (AppDomain.CurrentDomain.BaseDirectory).ToString();
sqlcon = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="+ domain + "selapp.mdf;" + "Integrated Security=True");
I hope you can help me, please
You will need to have LocalDB (SQL Server Express) installed on that computer that you copied the project (including the executable). This typically gets installed through the Visual Studio Installer (depending on the workload or components you select for installation). If you are planning on deploying your application to other computers you should look into setting up an installer project. This is where you would want to include the SqlLocalDB.msi (dependency) so that it gets installed with your application.
Related
I have created a Windows Forms desktop application using Visual Studio 2019. I also created a database using SQL Server Management Studio. I connected the database with my application with connection string
"Data Source=CYBERCELL\\SQLEXPRESS;Initial Catalog=Details;Integrated Security=True;"
The application is running without any error. I published this application using Visual Studio 2019 publish wizard and installed in another computer. But I can't understand how to use and connect the database with the application in that system.
I am looking to install SQL Server in every computer. But if I install SQL Server, the server name will be different.
If you're locally installing SQL Server Express on each individual computer, you could use
.\SQLEXPRESS
or
(local)\SQLEXPRESS
as your server/instance name - this is the same on every computer. The dot . or (local) (in parenthesis) refers to the local computer, and SQLEXPRESS is the default instance name for any SQL Server Express installation.
I once stuck with this same scenario... and this is how I solved the problem,
You don't have to install SSMS or SQL server on any of your client's pc, if you follow these steps
You have to create a localDB on your application and make sure the application will connect to that localDB.(if you don't know how to connect to local db, here => Connect to LocalDB. And make sure to create tables and procedures as same as your previous database.
Follow this answer(ticked) with code(connection string)
After this, you have to install Advanced Installer to create an installer for your application (the best choice I ever chose).
Then Follow this to create an installer where you make sure to add a prerequisite of localDB (say localdb 2019) installer of your current version.
This makes your application run on any pc and only requires localdb as a prerequisite to be installed which also comes with the installer.
Make sure to leave a message not to delete localdb on the application installed location.
I'm trying to publish C# Windows application. I tried to install shield and visual studio installer but it does not work properly.
This setup can install only on those laptops or PC in which visual studio is installed. can anyone help me what are prerequisites are required and how can publish installer setup.exe
app.config
connection string
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection_string"].ConnectionString);
but it occurs error
failed to update database because the database is read-only visual studio
You need to check the prerequisites. The .net version on which you have created the application will be required along with other prerequisites. It's not visual studio that is required to run the executable, but just the .net framework.
I have faced the same problem about how to get the setup file to work in any other device although it takes some time for me to understand the process but finally i have found that it's really simple.
1) you have to change the connection string to something like that :
string connectionStr = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True";
2) you can use Advanced Installer to generate the setup file, the process is simple, you can watch any short tutorial about how to get the setup file in Advanced Installer.
3) Finally, You have to install 3 programs as Prerequisites in client pc :
.Net Framework (I think started from version 4.5)
Sql Server Express
SSMS (Sql Server Management Studio)
I have just installed visual studio on a new windows 8.1 PC. When I try to run a new MVC project I get the following error when registring in the default mvc framework:
"Your sql server installation is either corrupt or has been tampered with (unknown package id)."
This is a brand new install and I have tampered with nothing. I saw it typically has to due with renaming your computer, but since this is a fresh install it shouldn't be an issue.
Please try the below mentioned options.
Change the name of the computer where it was originally might sort
this error.
Update the SQL server to the latest version and verify if it is compatible with installed visual studio.
If above option fails, then re-install SQL Server.
This error occurred because it might have got installed alongside with visual studio. Better install the version that is compatible with your system.
http://blog.sqlauthority.com/2009/05/28/sql-server-fix-error-sqldumper-library-failed-initialization-your-installation-is-either-corrupt-or-has-been-tampered-with-please-uninstall-then-re-run-setup-to-correct-to-correct-this-problem/
Fix/Workaround/Solution:
Go to Add/Remove Program in windows Control Panel
Remove “microsoft SQL server vss writer” program
Reboot the computer.
It's my first time to Deploy an Application which uses SQL Server Express Database.
I'm Using Entity Framework Model First to contact Database.
and i created a Setup wizard with Install Shield to Install the App.
These are Steps that I'v done to Install The Application in Destination Computer :
Installing MS SQL Server Express (DEST)
Installing The Program using Setup file (DEST)
Detach Database from SQL server and Copy Related .mdf ,.ldf file to the Destination Computer.
Attach database file in destination computer using SQL Server Management Studio.
I know server names and SQL name Instances are different and my program can't run correctly with the Old Connection String.
I'm Beginner at this, and I want to know what should I do in the Destination Computer to make the program run?
should I find a way to change the connection string on runtime?!
or is there any way to modify installshield project and it do this work for me? (installshield is professional edition)
could you suggest me what to do?
in my searches I saw that WiX can do this, but I find it complicated, and i don't have enough time to learn it. i need to deploy the app ASAP.
Thanks alot.
Few hints for using LocalDB in your project:
Download SQL Express LocalDB 2014 here. You can install it silently with single command like this
msiexec /i SqlLocalDB.msi /qn IACCEPTSQLLOCALDBLICENSETERMS=YES
Include your .MDF in your VS project and set in properties to Copy if newer so that it gets copied to your bin folder during build so that it is automatically included in the installer.
At your app startup (in app.cs) check, if database file exists in desired location (e.g. %PUBLIC%\YourApp\Data) (WPF Desktop Application with MDF used locally for all local users). If not, copy the .mdf file from your app install dir to your data dir.
Modify app.config so that your connection string looks like:
<add name="MyContextLocalDB" connectionString="Server=(localdb)\MSSQLLocalDB; Integrated Security=True; AttachDBFilename=|DataDirectory|\MyDatabase.mdf; Connection Timeout = 30" providerName="System.Data.SqlClient" />
Connection timeout should be increased, since LocalDB exe is launched when you first try to connect to it.
You can also use Database.CreateIfNotExists, but I have never tried it.
I have written a desktop application (Windows Forms) in .NET Framework 4.0 using Visual Studio 2010 and SQL Server 2008.
In the /bin folder, it creates an .exe file which works fine on my computer and other computers if they have Visual Studio and SQL Server installed. If they do not have these installed, then it gives report error and the .exe file does not run.
On another PC, I have tested it both on Windows XP sp3, Windows 7 after installing .NET Framework 4.0, and also installed Windows Installer 4.5 for WinXP sp3, but no success.
What is the problem? Is there anything wrong with my connection string which is:
#“Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
How can I make my .exe file run on other PCs?
Thank you, this helped a lot and now I understand the problem is only connection string but problem still not solved. Now I am using this connection string
Data Source=HOME-9BE0D501F6\SQLEXPRESS;AttachDbFilename=|DataDirectory|\shopdb.mdf;Integrated Security= True;User Instance=True
WA-PC was the name of my computer where I was working and it worked fine but when I copied the bin folder to my other pc with name HOME-9BE0D501F6 it still did not worked. I have changed the connection string in app.config file with this name but still got connection error. I have not installed SQL Server 2008 on this pc. Do I have to install it? What else I have to do?
.\SQLEXPRESS means SQL Express instance on local pc, so if no SQL Server installed, then you will get an error.
change the connection string with proper server name
Data Source=<servernameinwhichSQLServerInstalled>\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
If you are using (local) or DOT(.) It means that it has to connect to computer in which application is running. In this case if you dont have sql server or database installed on different computer it will throw this error.
The problem (as already mentioned) is that you are telling the SQL connection to use the local PC name and not the name of the server (where the SQL instance is installed).
A simple way to find this could be to open your SQL Managment Studio / Query Analyser / WinSQL / SQL Script editor and run the following script
use [Database name in question]
Select ##ServerName
Replace your;
Data Source=.\SQLEXPRESS
With
Data Source=##ServerNameResult\SQLEXPRESS
Hope that helps.