icCube connect to SQL Express file (.mdf) - connection

I read in this post that it is somehow possible to connect to SQL Express. This post is pretty old and I hope it is still possible somehow to make a connection to a .mdf file (SQL Express database).
How can you set-up a connection to this sort of file?

Related

MVC3 Problems After changing DB from SDF to MDF

Error:
An attempt to attach an auto-named database for file C:\Documents and Settings\xxx\My Documents\Visual Studio 2010\Projects\IncomeAndExpenditure\IncomeAndExpenditure\App_Data\Transactions.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
At the start of today I was happily accessing my MVC3 application's data in a SQL Server Compact Edition 4 .sdf data file. I now need to access this data from an Android app, but the Android app cannot connect to a .sdf file, it needs a connection to a .mdf file.
So I changed the database in the ASP.NET MVC app to a SQL Server Express and a .mdf file. So far so good, after much connection string changing the application runs under VS and connects to the new .mdf and allows read/write as expected.
Unfortunately now when I try to access the ASP.NET MVC app directly through a browser (I am running everything on localhost incl. VS, SSMS) I get the error as above. I have spent most of the day going back and forth as per many many posts here, MSDN and elsewhere to the point actually where the browser hung and I lost the will to live.
So after advice from the many posts this is I have tried so far in order to connect from both VS 10 and from MSIE 8 browser:
Placing database .mdf & log in SQL Server Express default data folder
Placing .mdf in |DataDirectory| (App_Data) folder
Adding new users in SSMS
Changing user permissions in SSMS
Altering User Instance=True / False in connection string
Attempting to connect after Attaching and detaching database .mdf & log files
My question:
Is there a straight forward guide somewhere that gives details of 'EVERYTHING' that needs to be done/considered when trying to swap a datasource from a SQL Server Compact Edition .sdf file to a SQL Server Express .mdf file?
I am using: XP, VS10, SQL Server 2008 R2, MSIE 8
Thanks, carl

SQL Server 2008 OLE DB CONNECTION FAILS FROM OUTSIDE

I have a working SQL Server 2008 R2 Express installed on a Windows 2008 server on a cloud machine. All type of connections (ado.net, nhibernate etc.) from several client applications works fine except the OLEDB one. SQL Native Client also works fine.
When I tried to connect from the server locally and as a data source write the instance name, everything was OK. But from outside, I had the problem or also if I write wan ip or dns I had the problem also from local.
-- works perfect from everywhere
Provider=SQLNCLI10;Data Source=mntek.no-ip.org;User ID=xxx;Password=xxx;
-- does not work from anywhere
Provider=SQLOLEDB.1;Data Source=mntek.no-ip.org;User ID=xxx;Password=xxx;
-- works only from local
Provider=SQLOLEDB.1;Data Source=flz001\sqlexpress;User ID=xxx;Password=xxx;
Error: [DBNETLIB][ConnectionOpen (Invalid Instance()).Invalid
connection.
-- works perfect with ado.net
Data Source=mntek.no-ip.org;User ID=xxx;Password=xxx
Some other client applications (not mine) was written with oledb connection so I need them to connect the db with oledb provider.
Any ideas?
Regards,
Mert
It has been a while since this was asked, but I am currently working through an issue related to OLE DB and SQL Server that sounds possibly related.
I found that, even though the server was using the default port (1433), I still had to explicitly specify it in the UDL connection string like this:
Provider=SQLOLEDB.1;User ID=USER;Data Source=IP,1433
I've asked why that might be necessary here:
Why might SQL Server 2008 OLE DB UDL require port 1433 explicitly specified?
Maybe try that and see if it helps.

MVC 3 Adding a local Database

I am currently going through the MvcMusicSore tutorial (MVC 3). I have full sql server 2008 installed and created a local database by running the SqL scripts included in the MvcMusicStore-Assets data folder. However when trying to add the mdf to the AppFolder in Visual Studio 2010 I get the error Access Denied. I am completely stuck at this point and would appreciate any help to resolve this.
Most probably the mdf file is locked by some other process, not allowing the application to read it. If you mounted the database on SQL Server you need to use a connection string with the machine name instead of specifying the mdf file directly.
You can't copy or modify a live working database. And I don't see why you should.
You need connecting to it? Pick a way. LINQ to SQL, Entity Framework, NHibernate, ADO.NET...
If you really want to copy the database file for some reason, you must first stop the MSSQL Service (or detach the database), then do that.
Like others have said, you shouldn't need to add the actual .mdf into your project. If you have it running on your local SQL Server instance, you should be able to add it via Visual Studio's Server Explorer (plus that gets you your connection string).

Forms Authentication with sqlite

I have an ASP MVC-application that uses a SQL server express for and Forms authentication. The server I'm using does not have enough memory to run SQL Server express stably and I was thinking about migrating to SQLite instead.
Is it possible to just migrate the existing aspnetdb-database from SQL Server to SQLite so that all my user accounts will be kept?
These shall help you perform such task:
SQLite Converter Tools
SQL Maestro (This one's not free though)
A good migrating tool project from Code Project
SO: convert sql-server *.mdf file into sqlite file
So, I guess that if such tools exist, it will then be possible to keep your data.
For security, perform a backup from your DB first!

When attaching a SQL Express DB via a connection string, is it an exclusive lock?

In .NET, you can open a SQL Express database simply by attaching the database MDF file in the connection string (that is, you don't have to have any server software installed, it just attaches to the MDF file on the fly).
When an application does this, does it obtain an exclusive lock on the database file? Or, can a second application also attach to and open the MDF file in this same way, and query the database while program #1 is using it?
You are correct, only a single connection can be open to the MDF at a time.
This can get really annoying when you open the database through your server explorer in Visual Studio, and then try to run your application.
I've caught myself doing that too many times to count, and I always invariably end up just attaching the mdf to my sql server instance.

Resources