-3

Ok, I come from the Open Source world where the "configuration" does not seem anywhere near this bizarre. I've been given a "mdf" database file. I am working with Visual Studio 2013 and all I want to do right now is simply bring up the dadgum page in Page Inspector or in the browser -- which I was able to do when I was connected to a "real" database in the office. But now I'm remote and need to work with this "file". I have put it in the "data folder of my project; I have put it in a folder in My Documents path; I have put it in Program Files path for MS SQl Server. The next place I'm going to put it is in the garbage unless I can find out how this "project" in Visual Studio 2013 is looking for a database. My "web.config" file has this:

    <add name="DefaultConnection" connectionString="Data Source=WS-xxxx;Initial Catalog=blahblahblah;MultipleActiveResultSets=True;Integrated Security=false;AttachDBFilename=|DataDirectory|blahblahblah.mdf;User Id=xxxxx;Password=yyyyy" providerName="System.Data.SqlClient" /> 

I've also tried:

    <add name="DefaultConnection" connectionString="Data Source=WS-xxxx;Initial Catalog=blahblahblah;MultipleActiveResultSets=True;Integrated Security=false;AttachDBFilename=[C:\Users\MyName\My Documents\Test Database\blahblahblah.mdf;User Id=xxxxx;Password=yyyyy" providerName="System.Data.SqlClient" /> 

...and this:

     <add name="DefaultConnection" connectionString="Data Source=WS-xxxx;Initial Catalog=blahblahblah;MultipleActiveResultSets=True;Integrated Security=false;User Id=xxxxx;Password=yyyyy" providerName="System.Data.SqlClient" /> 

Nothing else seems to make much sense. I'd appreciate any (valid) advice on why this is happening -- I was hoping to be coding in C# at this point, not fighting with MS Configuration stuff. As info, I CAN see the database in both Server Explorer and SQL Server Object Explorer in the VS Studio. I can also query it IN THE STUDIO and get valid results. And it's at the path that I specified in the "My Documents" folder. So it boggles my mind that I have put all these various paths in this web.config file and the Studio still says it can't find it when I bring up Page Inspector. Thanks.

This is the error I keep getting, regardless of where I put this database:

The system cannot find the file specified Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
McAuley
  • 413
  • 1
  • 3
  • 13
  • This probably has something to do with either your code, or your database server. Since we can't see either one, there's no way to help you. Read the exception message. It's pretty clear. – John Saunders Jan 14 '15 at 02:46
  • 1
    There are some suggestion to follow here: http://stackoverflow.com/questions/173209/how-do-i-connect-to-an-mdf-microsoft-sql-server-database-file-in-a-simple-web. I feel your pain.... fighting with annoying config stuff that's meant to make life easier but you end up wasting hours to get it to work. – Nick.Mc Jan 14 '15 at 02:59
  • 1
    Also a 'practical' approach would be to use ProcMon to see for yourself where the thing is actually searching for the file.. also I would make certain that this particular line is not actually trying to _create_ that file when you run it (as opposed to just using it) – Nick.Mc Jan 14 '15 at 03:12
  • 2
    If you can see the database in Server Explorer in VS 2013, I assume it is listed under "Data Connections". If so, right click on the database name in Data Connections, and go to Properties. One of the properties is "Connection String". Try that. – Solomon Rutzky Jan 14 '15 at 03:19
  • Ok, now I've added this to the connection string: "AttachDBFilename=[C:\USERS\MyName\DOCUMENTS\Test Database\VMADATALINKDB_KEN1.MDF];User Id=xxxxx;Password=xxxxxx" . I left the provider name as System.Data.SqlClient. Now I get a different error msg, but I've gotten this one before: The given path's format is not supported. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. – McAuley Jan 14 '15 at 04:08
  • But there is nothing in those error messages I can see that indicate what the "real" problem is. FYI, the Project code worked fine in the office with a DEV database on a network server, and yeah, I've changed the connection because I need to point to a LOCAL Db file. This is "Code First" C#, and I'm not really at liberty to mess around with the code except for my personal config. just want to display a page for right now. Thanks – McAuley Jan 14 '15 at 04:17
  • 1
    Why are you adding square brackets around the path? Those aren't valid characters for a path. Just use: `AttachDBFilename=C:\USERS\MyName\DOCUMENTS\Test Database\VMADATALINKDB_KEN1.MDF;User Id=xxxxx;Password=xxxxxx` – Solomon Rutzky Jan 14 '15 at 18:15

1 Answers1

1

If you can see the database in Server Explorer in VS 2013, I assume it is listed under "Data Connections". If so, right click on the database name in Data Connections, and go to Properties. One of the properties is "Connection String". Try that.

And be sure to not add square brackets around the file path as those aren't valid characters.

Your config tag should look something like:

<add name="DefaultConnection"
     connectionString="Data Source=WS-xxxx;Initial Catalog=blahblahblah;MultipleActiveResultSets=True;Integrated Security=false;AttachDBFilename=C:\Users\MyName\My Documents\Test Database\blahblahblah.mdf;User Id=xxxxx;Password=yyyyy"
     providerName="System.Data.SqlClient"
/>
Solomon Rutzky
  • 46,688
  • 9
  • 128
  • 171
  • It turns out that I was using the wrong 'config' in the "Solutions Configuration" in Visual Studio. There are 7 of them and I simply didn't notice because I'm new to this tool. But the answer I selected was very helpful in setting up and correcting the configuration that I ended up using. – McAuley Jan 24 '15 at 21:09