-1

I can't connect to my locally DB, it's working fine on the live version. Live version is SQL Server 2012 and test enviroment is SQL Server 2014 Express.

I'm using Web Matrix 3 and a Visual Studio 2013 debugger attached to the process, but I've tried almost everything now? I think the problem is related to connection issues. But i can of course connect to the DB from Management studio.

Here is my connection strings

  <connectionStrings>
    <add name="ConStrLive" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=lastbilmagasinet_dk;Persist Security Info=True;User ID=lastbilmagasinet;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrDev" providerName="System.Data.SqlClient" connectionString="Data Source=DVSRV;Initial Catalog=lastbilmagasinet_dk;Persist Security Info=True;User ID=intern;Password=xxxx!;Max Pool Size=10000" />
    <add name="ConStrLB" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=lastbilbasen_dk;Persist Security Info=True;User ID=lastbilbasen;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrLMBanner" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=lmbanner_dk;Persist Security Info=True;User ID=lmbanner;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrFragtbasen" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=fragtbasen_dk;Persist Security Info=True;User ID=fragtbasen;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrTransjob" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=transportjobbasen_dk;Persist Security Info=True;User ID=transportjobbasen;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrLastbilshow" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=lastbilshow_dk;Persist Security Info=True;User ID=lastbilshow;Password=xxxx;Max Pool Size=10000" />
    <add name="ConStrTruckpadborg" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=truckpadborg_dk;Persist Security Info=True;User ID=truckpadborg;Password=xxxx;Max Pool Size=10000" />
  </connectionStrings>

Anybody got any ideas?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
  • checkout this site for how to configure your connect string in C# to your local DB [C# Connection Strings](http://www.connectionstrings.com) also the error message is telling you what's wrong..it can't find a specified file.. are all of the .cs files in your project using namespace or the same namespace..? – MethodMan Feb 26 '15 at 15:27
  • what are you talking about `From my web.config` can you show the full code block in regards to when the error is being thrown.. also have you put breakpoints in the code to step through and identify the exact line that's throwing the error..? – MethodMan Feb 26 '15 at 15:32
  • paste that into your original question please.. also I have provided you a link in my initial comment with how to configure connection strings in C# go to that link and select your DB that you are using and there are great examples there – MethodMan Feb 26 '15 at 15:39
  • And that i wrapped inside Can post all connentions string because lack of characters – Alex Sleiborg Feb 26 '15 at 15:40
  • It won't show the XML in the original post – Alex Sleiborg Feb 26 '15 at 15:41
  • if you format the code properly it would delete the unnecessary stuff and post the relevant stuff... I edited your code for you.. now you need to edit and post the code that reads the web.config file where you are trying to call / assign the connection string also look at that link there are working examples on there look at my first comment and click on the C# ConnectionStrings it will take you to the site to show how to configure connection strings also change your `127.0.0.1 to (localhost)` – MethodMan Feb 26 '15 at 15:43
  • The MS SQL 2014 express isn't listed. The newest is SQL 2012 – Alex Sleiborg Feb 26 '15 at 15:49
  • doesn't matter Sql connection strings from what I have seen as well as used in the past work.. give it a try and stop being so hesitant – MethodMan Feb 26 '15 at 15:51
  • SqlConnection conn = new SqlConnection(SiteConfig.ConnStr); using (conn) This reads the connection string, and it looks fine with the debugger attached. I've looked in C# connection strings website 5 hours ago. Perhaps the MSSQL user isn't correctly created? – Alex Sleiborg Feb 26 '15 at 15:54
  • you need to google how to get connection string from web.config file are you familiar with the following `ConfigurationManager.ConnectionStrings` please show some more effort here is a good site that's good for finding things like this and I know it works from your current location [C# ConfigurationManager.ConnectionStrings](http://www.google.com) – MethodMan Feb 26 '15 at 15:56
  • Why should there be any problem with ConfigurationManager.ConnectionStrings when the site is working properly live. But not locally, the only difference is the MSSQL server? I've already searced Google for about 5 hours, with no luck at all. And no properly error message – Alex Sleiborg Feb 26 '15 at 15:59
  • I think you are not understanding the local issue has to deal with how your database is configured.. do you have it configured for example to recognize `namedPipes` how is the actual local database named you can totally find this out by looking at the properties in sql management studio express also I have never had issues with my application web app or win app or console app ever locating the .config file using `ConfigurationManager` it's really hard to tell without truly knowing how you created / setup the database name.. – MethodMan Feb 26 '15 at 16:01
  • Hi again. Your surely right, but I rather not change to much in the codebase, because I have to make a commit after i'm done, and deploy for the live website. So of course I can reverse to an earlier commit, but it will be time consuming. Me experience with MSSQL is very limited, thats we im asking in this forum. So the optimal solution for me would be to get the local DB configured correctly. But i'll look into some of your ideas. – Alex Sleiborg Feb 26 '15 at 21:13

1 Answers1

0

The problem was the Datasource. Apparently MSSQL doesn't allow 127.0.0.1 or localhost as local Datasource, or mine which was default configured didn't anyway.

So the datasource in the connection string had to be WIN-BD4MCUAKPRP\SQLEXPRESS. Then it worked :)