-1

I've been creating a local off-line program in c#, following tutorials and learning as I go. I learned to create SQL Server databases and connect to them through the model first tutorial on MSDN. My application is working at the moment but only on my computer.

I noticed this when I tried testing it on another laptop, without Visual Studio installed. The error that comes up reads

The underlying provider failed on Open

I'm not really sure why this is occurring and after researching this topic and reading several articles none of them have fixed it.

The SQL file was generated from an ADO.net model if that helps

The connection string as auto-generated by Visual Studio is as follows (formatted for readability):

data source              = (localdb)\v11.0;
initial catalog          = RandomInputMachine.logIn;
integrated security      = True;
MultipleActiveResultSets = True;
App                      = EntityFramework

SQL Server version is 2012

Specific code where error occurs:

// Display all users from the database 
var query = from b in db.Users1
            select b;

Console.WriteLine("All users in the database:");
foreach (var item in query)
{
    if (!deleteAll)
    {
        Console.WriteLine("---------------------------------------------------");
        if (item.username != "agentender" || Program.user == "OVERIDE")
        {
            Console.WriteLine(item.username);
        }
        if (item.username == txtUser.Text)
        {
            if (item.password == GetHashedString(txtPass.Text, item.salt))
            {
                Program.user = item.username;
                Program.loggedIn = true;
            }
        }
    } else {
        db.Users1.Remove(item);
    }
}

How can I work out what is wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Craigory Coppola
  • 647
  • 4
  • 13
  • 3
    Is SQL Server 2012 or later installed? What connection-string are you using? – Dai Nov 18 '14 at 22:15
  • Dai i added the info you requested – Craigory Coppola Nov 18 '14 at 22:20
  • BTW: we can assume you use sql server, but it is not clear in your question what DB you are using. – L.B Nov 18 '14 at 22:21
  • have you looked at [ConnectionStrings](http://www.connectionstrings.com) site it has examples of how to write a valid connection string in your .config file – MethodMan Nov 18 '14 at 22:24
  • 1
    Three items that will cause this error: 1) SQL Server is not installed on your test machine. 2) Connection string signs into SQL Server using the current user's account. If current user doesn't have an account on the local SQL Server, sign in fails. 3) RandomInputMachine might not exist as a database on the test machine's SQL Server installation. – StarPilot Nov 18 '14 at 22:39
  • @DJKRAZE - SQL Server uses (local) to mean the default instance, and (localdb) means to use the default instance in process (ie, the SQL Server code runs on the calling thread, and not as a stand alone server). – StarPilot Nov 18 '14 at 22:40
  • I am aware of that I should have restated it as I have not normally seen this convention outside of running a local instance vs trying to connect remotely.. – MethodMan Nov 18 '14 at 22:47
  • @StarPilot that is incorrect. SQL Server does not run in-process with `localdb`, instead it creates a new instance of `sqlserver.exe`. – Dai Nov 19 '14 at 02:32
  • @Dai - The SQL Server group states "LocalDB process is started as a child process of the application. A few minutes after the last connection to this process is closed the process shuts down." (from http://blogs.msdn.com/b/sqlexpress/archive/2012/05/07/10184083.aspx ) If LocalDB is a child process of the calling application, this still implies that it is in effect in-process (using the calling APPLICATION, not the SqlServer.exe service resources). – StarPilot Nov 19 '14 at 17:27
  • @starpilot that's not what "child process" means. – Dai Nov 19 '14 at 18:36

1 Answers1

1

The problem is one or more of the following:

  1. SQL Server is not installed on your test lap top.
  2. The database file is not found or not available at the current permission settings.
  3. You do not have permissions on the test lap top's SQL Server installation.
  4. The test lap top's SQL Server does not have a database named RandomInputMachine as you specify in your connection string.

SQL Server Express is free to install. It can be found at Microsoft SQL Server Express Edition home page

StarPilot
  • 2,246
  • 1
  • 16
  • 18
  • do you happen to have a link for SQL Server? i tried installing Visual Studio but that did not help – Craigory Coppola Nov 18 '14 at 22:58
  • @AgentEnder - Just updated the answer with a link to SQL Server Express. It's the free version of SQL Server that Microsoft provides to any one that wants it. Uses the same code as the paid for SQL Server editions. It is what is bundled inside Visual Studio. – StarPilot Nov 18 '14 at 23:01