Publishing a VB.NET Application with SQL Express DB (using LocalDB) - sql-server

I have written a VB.Net application that uses an SQL Express DB file containing a single table and a handful of stored procedures.
I have successfully built and exported the application to my VPS.
The problem comes when knowing what to do concerning the database file, there is a wealth of stuff online but not specifically to suit my needs.
I plan to use LocalDB on the VPS but being commandline - it is hard to know if the scripts that I have run have been successful after creating an instance , starting it... etc,
I want to keep installation requirements to an absolute minimum on my VPS machine and (in time other end users machines)... hence using LocalDB and not SQL Express
So, what do I have to do on the VPS to enable my application to connect to the database.. ? This was simple when it was Access - (supply the MDB file and run the AccessDatabaseEngine(redistributable) - job done)
The connection on my devt. machine runs as expected.
The connection string in my code is:
Const strSQLConnection As String = "Data Source= (localdb)\v11.0;Database=SoccerTrader;Trusted_Connection=True"
Can anyone help please.. this is driving me around the bend.. surely it cant be that difficult..?
===========================
I have found the following in an MSDN blog which says:
Database as a File: LocalDB connection strings support AttachDbFileName property that allows attaching a database file during the connection process. This lets developers work directly with databases instead of the database server. Assuming a database file (*.MDF file with the corresponding *.LDF file) is stored at “C:\MyData\Database1.mdf” the developer can start working with it by simply using the following connection string: “Data Source=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\MyData\Database1.mdf”.
================ ADDED 12th June =====================
OK, this is really bugging me now... I have read around this till it is coming out of my ears and nothing specifically seems to target what I am trying to do. All the blogs I read refer to installing / running SQL Server and changing permissions etc.
As I have mentioned I am using a VPS and propose to use LocalDB on the VPS to access a simple/small database file for a VB.Net application I am writing.
This is the story so far.
1) I have built a working prototype on my development PC and connected using SQL Express to a database file SoccerTrader.mdf - no problem.
In the Visual Studio Project properties I have added a requirement to the project that checks for SQL Server ..and if it is missing, installs it...
2) I install the project on the VPS and as expected SQL Server 2012 LocalDB is installed .... see here..
3) I have copied the SoccerTrader.MDF and SoccerTrader.LDF files into "C:\BESTBETSoftware\SoccerBot" on the VPS
4) for practical reasons given the problems I am having getting this to work, I have implemented an inputbox for me to specify the connection string when the application runs.... the connection strings I have used give the following...
1]: http://i.stack.imgur.com/i2tro.png
I have not changed any file permissions on the development PC and the database state is NOT read only....
So, the question is where do I go from here...? What have I missed.. why is it not working..?

I have managed to sort the problem.
Seemingly, the connection string I was using was OK. It was my error handling that wasnt 'clean' enough. It transpired the connection was being made on my VPS but when the application attempted to update the table , the directory I had created and put the MDF file into, would not permit write access.
I moved the MDF into the C:\Users\Public\Documents folder and all works as it should.

You have to specify the full path of the Db file with folder name/ip-address

Related

VS2019 MVC Database solution won't work on a second machine

I had created a webpage with DB access which works perfectly well on the machine I develop it. However, when I copy everything across to another machine, it fails with an error message - cannot open database xxx requested by the login. I did copy everything including the database created in the development environment and put it in the same place as the development did. What other thing I had done wrong ? Please help. In addition, when I open the solution on another machine, I cannot see the database from the SQL Server Object Explorer like what I saw on the development machine.
Problem solved ! Need to copy the database and the log file across and the used the SQL Server Manager to attach the database to the right server. After that, everything just work !!

SQL Server Express, Windows 7, Visual Studio 2017

As a .NET Desktop developer, I have a lot of experience working with various databases that are already up and running; but I'm not a DBA. I'm currently working at a company where I am ther only software guy here to build them software from scratch -- their previous enterprise-level solution was an Access database with macros and a couple forms built it. So, I basically have no one else to go to.
With that preface, how the heck do I get a database -- ANY DATABASE!!! -- added to my VS solution? I've been beating my head against this for almost 6 hours and have made zero headway. At this point, I'm ready to say, "Screw MS databases!" and start looking at MySQL or PostgreSQL or something.
The desktop application I'm developing has to work whether there is an internet connection or not, so I need a local database that installs with ClickOnce. From what I've found so far:
SQL Server [Express] 2016+ requires Windows 8 or later (a non-starter since 95% our customers are still running Windows 7)
SQL Server Compact is being deprecated and won't work past VS2013
I think LocalDB is what replaces Compact in 2016+ (?)
Okay, so I started with this tutorial:https: //learn.microsoft.com/en-us/visualstudio/data-tools/create-a-sql-database-by-using-a-designer However, trying to add a "Service-based Database" just gives me this error once: "The 'DBProviderFactories' section can only appear once per config file." I try again and get this error repeatedly: "Unable to find DbProviderFactory for type System.Data.SqlClientConnection" I've Googled both errors and all the answers that I've been able to find pertain to VS2010 or earlier and their solutions are either not applicable or don't work.
Next, I tried this tutorial: https://msdn.microsoft.com/en-us/library/aa983322.aspx I've tried adding new data connections through the "Server Explorer" panel. I don't see "[*] Compact" as an option. When I try "Microsoft SQL Server Database File", I just get the error: Unable to find the requested .Net Framework Data Provider. It may not be installed."
I've even tried adding data sources through the "Data Sources" panel; that doesn't work either.
I've installed the "Data storage and development" addon from the Visual Studio Installer, several versions of SQL Server 2014, SQL Server Compact 4.0, and maybe a few other executables from Microsoft's website.
Nothing works.
Help...
I think I just found it!
Evidently, there are "machine.config" files on your computer. Search for them all, and make sure that there is only a single tag for "DbProviderFactories". I can add a database object now. Hopefully, this puts me in business...
https://social.msdn.microsoft.com/Forums/vstudio/en-US/7b4f353b-77fd-427c-976b-5968abc88c13/visual-studio-2010-unable-to-find-the-requested-net-framework-data-provider-for-sql?forum=vseditor
If what you are saying is that you are writing a browser based application - then one would migrate the tables to SQL Server (Express) or even MySQL - it really doesn't matter. Then write a new web app. The existing Access app would serve as a model for seeing features & screen layout but is otherwise not portable.
On the other hand, if you are re-writing a Windows application; then the decision is whether the payload requires a server solution or if one can stay at the PC level. If the payload is suitable for PC then a re-write using either Visual Studio or Access again.
Access is a front end db - the tables in the back end whether they be stored in SQL Server or an Access file are entirely passive. All the processing is done by the user's PC. If the payload allows that then this is the lowest cost re-write option.
If you've outgrown a PC level payload - then one must develop a back end database feature set with a more passive front end.

How to create sql Database in installshield express?

I recently developed a winform application with c# and SQL Server 2008 data access. I want to create an "InstallShield express" setup file for it (I don't want to use ClickOnce or Setup And Deployment witch is available in VS). I want to create a db or attach it to SQL server instance after installing SQL Server Express 2008 SP3 (not local db). What is the best way to do this?
Your question is quite vague as you do not explain what kind of “app”, “setup file” or “db” you are using, nor how you “attach it to sql”. In the future, please include these details. However, I can give a general answer.
Create a seed database, that contains the starting data for your application, in your source project.
Add the seed database file to your project/solution file and set its Build Action to “Content”.
Ensure your installer includes project content in the deployment folder (the application folder for WinForms apps).
To open the seed database from your app, use a connection string like Data Source=|DataDirectory|seed.sdf. Do not try to search for your seed file or to set DataDirectory yourself; the installer will set DataDirectory to the directory your content was installed to.
Do not try to write to DataDirectory; it may not be writable by the user who installed it. Repairing the app will overwrite DataDirectory, destroying anything you saved there, as well.
If you need to save data in the database, copy |DataDirectory|seed.sdf to Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), then read and write all data to the copy.
For more information, read my answer to a poster who wrote to |DataDirectory| and therefore kept destroying his user's data.

Error on compile or run the application on VS2010 & SQL Server 2012 Express

I'm getting an error when I try to compile or run the application.
Performing a simple tutorial, I worked at first but now when I generate the project F6 or try to run it, I always get the error
Error 1 Unable to copy
"C:\Projects\DatabaseExampleApp\DatabaseExampleApp\App_Data\northwnd.mdf"
to "bin\Debug\App_Data\northwnd.mdf". The process can not access the
file 'bin\Debug\App_Data\northwnd.mdf' because it is being used by
another process. DatabaseExampleApp
The first time when I run the app worked fine
I'm using:
Visual Studio 2010 Professional
SQL Server 2012 Express 64-bits
EDIT:
after:
kill the sqlservr.exe (is the file locker)
delete the files myself northwnd.* northwnd_log.*
generate project F6
run the app work fine
But I have a questions:
how kill or unload the file northwnd.mdf to avoid this problem?
The app compile after that but don't run
You're not showing us your connection string, but I'm assuming you're using some kind of AttachDbFileName=.... approach.
My recommendation for this would be: just don't do that. It's messy to fiddle around with .mdf files, specifying them directly by location, you're running into problems when Visual Studio wants to copy that file around - just forget about all that.
I would
create the database on the SQL Server Express instance (CREATE DATABASE ..... in Mgmt Studio)
talk to the database by its logical name - not a physical file name
So I would put my database onto the SQL Server Express server instance, and then use a connection string something like this:
Server=.\SQLEXPRESS;Database=MyShinyDatabase;Integrated Security=SSPI;
No messy file names, Visual Studio won't have to copy around files at runtime or anything, your data is on the server and can be used and administered there - seems like the much cleaner and much nicer approach to me.

Changing connection to SQL Server in Microsoft Access 2003 ade file

I developed an Access 2003 application that is connected to SQL Server.
My problem is that I developed the software on my server, and the application runs on the client network on a different (identical) server.
As a result my executable file (Aka. .ADE) does not open on the client's computer, because of bad SQL Server connection.
My solution so far was to open the application file (.ADP) on the client's computer, changing the connection path from there and then creating there the executable file.
Now my client has only Access runtime environment, so I cannot do such thing.
I wonder if there is a way to determine the connection in an ADE file this way.
(I know I can change it through VBA, but when the connection is initially false, I don't even get to the VBA code stage.)
In the interest of keeping things simple, I'll say you need to set up a testing environment you control that mimics your client's environment. For instance, if they have a sql 2008 server named "SQL1", then you should install sql 2008 express on your machine, and rename your machine to "SQL1" so you can test. You'd also need to copy the schema of their database tables and put that same schema in your own test database, and fill it with test data that is similar to theirs. And you'll want to create duplicate logins as well.
With all that in place, I wouldn't think you'd need to update anything. Just copy the ADE file over to your client when you're done making changes. You could try to code your way though this scenario, but I've been there and done that. Having a test environment that apes your client's takes a lot of headaches out of the equation.

Resources