Problems with connecting locally to SQL Server 2014 Express - c#

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?

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 :)

Related

Connection string is not working while using (data source =.\SQLExpress)

I'm using ASP.NET with C# and SQL Server
T have to use my .mdf file inside the App_Data folder because I don't have access to the SQL database.
T have a problem with this connection string only if T use .\SQLExpress
<connectionStrings>
<add name="msscEduConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MsscEdu.mdf;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
This connection string is not working and it shows error with attaching database
We have another site with connection string like this but different name and it works fine.
This is the connection string for the other site
<connectionStrings>
<add name="msdschoolkjConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\msdschoolkj.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
If I use the following connection string it works only on my computer but not the server
<connectionStrings>
<add name="msscEduConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MsscEdu.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Can anyone assist?
Try this in your web.config file
<connectionStrings>
<add name="ConnectionName"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Connect to SQL Server in web.config (ASP.NET MVC) using Windows authentication not working, why?

It is under configsection but it's not working and it didn't connect to SQL Server. Can anyone help me with this problem?
Of course, my data source name is . not other thing.
<connectionStrings>
<add name="CompanyContext"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Learning_EFCF;"
providerName="System.Data.SqlClient" />
</connectionStrings>

Entity Framework connection string error

I have this connectionstring in app.config
<appSettings>
<add key="CBREEntities" value="metadata=res://*/CBRE.csdl|res://*/CBRE.ssdl|res://*/CBRE.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" />
<add key="elmah-sqlserver" value="data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True" />
</appSettings>
and this in web.config.cshtml
<connectionStrings>
<add name="CBREEntities" connectionString="#Model["CBREEntities"]" providerName="System.Data.EntityClient" />
<add name="elmah-sqlserver" connectionString="#Model["elmah-sqlserver"]" providerName="System.Data.SqlClient" />
</connectionStrings>
Entity framework generates this connection string in web.config file
<connectionStrings>
<add name="CBREEntities" connectionString="metadata=res://*/CBRE.csdl|res://*/CBRE.ssdl|res://*/CBRE.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
<add name="elmah-sqlserver" connectionString="data source=.\SQLEXPRESS;initial catalog=aqp4ewzly1-bp_toolkit_prd_0006-20160923T050628Z;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
and after running app I have this error
It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
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: StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING
already tested replacing ' with " and replacing entityclient to sqlclient
Try delete your connectionStrings in your web.config.cshtml
I'd never put connectionstring in web.config.cshtml and all my applications woks fine.
I hope help!

WPF app SQL connection string error

This question has probably been asked a thousand times but all the answers that I have seen are not relevant to my question.
I have an asp.net web site setup locally to connect to sql and I used the exact same connection strings in the WPF App.config file
<connectionStrings>
<add name="TrackingConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SHIPPING; User Id=sa; Password=password" />
<add name="RMAConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=FRTOOLSRMA; User Id=sa; Password=password" />
<add name="PickListConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=Picklist; User Id=sa; Password=password" />
<add name="ShipWorksConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=ShipWorks; User Id=sa; Password=password" />
<add name="SupplyConnection" providerName="System.Data.SqlClient" connectionString="Data Source=RAIDSHIPPING\FRTOOLS; Initial Catalog=SupplyManager; User Id=sa; Password=password" />
</connectionStrings>
As usual this works on the local machine but on the network machine I get a "A network-related or instance-specific error occurred while establishing a connection to SQL Server." error.
Like I said this connection string is copied exactly from the asp.net web application, web.config file connection string which the network machine consumes fine. I have the App.config properties set to Copy always also the Sql server configuration is set up to enable Named Pipes and TCP/IP. Windows Firewall has port 1433 open. I thought the Copy always property being set would have solved the problem since the program wouldn't work because images were causing it to break until I set their properties to copy always. I've restarted the SQL Server and machine.

How do I build the database connection string if the website is on the same server as the db?

I have a problem with my connection string and I couldn't find anything on the web that could help me. So I have a test website on which I connect to a database which is not on the same server. There it all works fine, the data is being read correctly and the connection is successful.
Now when I try the same on a website which is on the same server than the database it doesn't work. So I figured I can't just connect to the database server as I would from a different server if I am already on that server like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=serverName;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Could anyone help me with that?
If you need more information just ask please.
Thanks in advance!
[edit]
Oh I forgot...this is the error message I get:
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)
Try localhost instead of server name
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=localhost;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
Both answers above are correct, however, if you have SQL Express installed (I assume we're talking about MS SQL) then your connection string must be something like this:
<connectionStrings>
<add name="nameOfConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=databaseName;User ID=userName;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>

Categories

Resources