SQL Server connection string problems - sql-server

I am trying to have access to my project from the browser, I have put it on my server .
My database is on SQL Server 2008 R2 .
When I try to login I have always this exception :
Invalid value for key 'attachdbfilename'
I think the problem is from my connection string but I can't fix it . I tried in many ways .
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Initial Catalog=DataUi;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|DataUi.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can someone help me ?
Thank you very much .

The AttachDbFileName= feature is available ONLY in the SQL Server EXPRESS edition. It is NOT compatible and supported on a "full" SQL Server installation.
If you have a full SQL Server, you have to attach your database to the SQL Server instance, and then reference it by its (logical) database name - not the physical file name:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="server=.;database=DataUi;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>

You should "Database" rather than "AttachDbFileName" as it is not recommended for production servers.
Hence your connection string should be:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Initial
Catalog=DataUi;Integrated Security=SSPI;Database=DataUi.mdf;User
Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>

I think there's a missing \\ in your AttachDBFilename right after |DataDirectory|:
AttachDBFilename=|DataDirectory|\\DataUi.mdf

Related

SQL Server connection string to use windows account [duplicate]

I am creating a website, but in the database I use windows authentication.
I know that you use this for SQL authentication
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
user id=sa;password=P#ssw0rd"
providerName="System.Data.SqlClient" />
</connectionStrings>
How do I modify this to work with windows authentication?
Replace the username and password with Integrated Security=SSPI;
So the connection string should be
<connectionStrings>
<add name="NorthwindContex"
connectionString="data source=localhost;
initial catalog=northwind;persist security info=True;
Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
For connecting to a sql server database via Windows authentication basically needs which server you want to connect , what is your database name , Integrated Security info and provider name.
Basically this works:
<connectionStrings>
<add name="MyConnectionString"
connectionString="data source=ServerName;
Initial Catalog=DatabaseName;Integrated Security=True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Setting Integrated Security field true means basically you want to reach database via Windows authentication, if you set this field false Windows authentication will not work.
It is also working different according which provider you are using.
SqlClient both Integrated Security=true; or IntegratedSecurity=SSPI; is working.
OleDb it is Integrated Security=SSPI;
Odbc it is Trusted_Connection=yes;
OracleClient it is Integrated Security=yes;
Integrated Security=true throws an exception when used with the OleDb provider.
For the correct solution after many hours:
Open the configuration file
Change the connection string with the following
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
Change the YOUR_SERVER_NAME with your current server name and save
Open the IIS Manager
Find the name of the application pool that the website or web application is using
Right-click and choose Advanced settings
From Advanced settings under Process Model change the Identity to Custom account and add your Server Admin details, please see the attached images:
Hope this will help.
This is shorter and works
<connectionStrings>
<add name="DBConnection"
connectionString="data source=SERVER\INSTANCE;
Initial Catalog=MyDB;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Persist Security Info not needed
If anyone comes looking for asp.net core, we will have to add connection string in appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Server=SQLServer\\Instance;Database=MYDB;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Source: add windows authentication sql server connection string

Connect EF to SQL Server Management studio

I'm using EF code-first and I want it to create the new database in SQL Server Management Studio instance instead of using the integrated SQL Server in Visual Studio.
I added this to my web.config:
<connectionStrings>
<add name="BillFo"
connectionString="Data Source=SELANL293;Initial Catalog=Billfo;Integrated Security=True"/>
</connectionStrings>
But it doesn't help. No nothing happens, nothing in the integrated SQL Server and nothing in my SQL Server Management Studio. How do I make it create my database in Management Studio rather then the SQL Server in Visual Studio?
try add this section
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="connection string......"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="..." providerName="System.Data.SqlClient" connectionString="......" />
</connectionStrings>
you do not have to use <parameters> property , you can use your currently connection string configuration
Try
<connectionStrings>
<clear />
<add name="YourEFContextName" connectionString="Data Source=localhost\SqlServerInstanceName; Initial Catalog=DataBaseName; User ID=UserName; password=YourPassword; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
The section entityFramework should be created automatically.

2 DNN filesystems pointing to the same database

I have setup a local installation of DNN7 using a database residing in another machine (sqlserver 2008).
I've tried to copy all the filesystem to a production server but keep the connection string the same, so use the exact same database.
I get the message
"The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty."
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
The application pool and IIS settings are the same in both machines. Any ideas of what am I missing?
You are missing following section in web.config
<connectionStrings>
<!-- Connection String for SQL Server 2005/2008 Express -->
<!-- Connection String for SQL Server 2005/2008
<add name="SiteSqlServer" connectionString="Server=(local);Database=DotNetNuke;uid=;pwd=;" providerName="System.Data.SqlClient" />
-->
</connectionStrings>
The problem had to do with the role membership provider.
For some reason the AspNetSqlMembershipProvider provider falls back at the default one which is in the machine.config (insided the .NET folder).
In dev environments with an SQLEXpress instance running, the machine.config has a connection string named 'LocalSqlServer' which points to the SQLExpress. That's why it worked in my dev environment.
The server on the other hand, doesn't have SQLExpress, so no LocalSqlServer connectionstring exists in the machine.config and therefore the error pops up.
The workaround I found in DNN forums is to add these lines inside the section of the web.config
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=dbserver;Integrated Security=false;Initial Catalog=dbName;User ID=dbUser;Password=dbPass" providerName="System.Data.SqlClient" />

Unable to Connect with SQL Server Authentication

I'm creating a simple ASP.NET MVC 4 application using Entity Framework and code-first. With SQL Server Express 2012, everything works fine when using Windows Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
However, when using the following for SQL Server Authentication:
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; AttachDbFilename=|DataDirectory|myDb.mdf;Integrated Security=False; User Id=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
I receive an error:
"Login failed for user 'mysa'" ProviderIncompatibleException.
Am I missing something?
Is it possible that your *.mdf file is not attached to sql server instance?
Try attaching the myDb.mdf file to your database with SQL Management Studio and the change the connection string to
<add name="dbConnectionString" connectionString="Data Source=(localdb)\v11.0; Category=myDb;Integrated Security=False; User=mysa; Password=mysapassword" providerName="System.Data.SqlClient" />
and don't forget to give the appropriate rights to your user

Sql Authenticated Connection String for AspNetDb

Before I begin I would like to say I have already checked thoroughly at www.connectionstrings.com and looked at all possible threads at this forum for an answer.
Right now my connection string is like this:
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
Its working, but I can only access it in my App_Data folder
I want to access this database from the SQL SSMS, therefore I have tried changing it like this:
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
Database=AspNetDb;InitialCatalog=ASPNETDB; User Id=kaneXtreme;Password=password123!;User Instance=true" providerName="System.Data.SqlClient"/>
I have also tried this
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Database=AspNetDb;
Initial Catalog=ASPNETDB; User Id=kaneXtreme;Password=password123!" providerName="System.Data.SqlClient" />
Both of which I have tried changing is resulting in this Configuration error when I open up localhost:
The entry LocalSqlServer has already been added.
Advice please.
You could try to clear your connection strings before adding the first one.
By default, there is a "hidden" LocalSqlServer connection string in your machine.config
<connectionStrings>
<clear/>
<add name="LocalSqlServer" and-so-on-and-so-forth ...
If your using a username and password I think you need to change Integrated Security=SSPI to Integrated Security=True
eg.
<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB;User id=kaneXtreme password=password123!;Integrated Security=True;" providerName="System.Data.SqlClient" />

Resources