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" />
Related
I have two servers: AppServer with IP 192.168.1.2 and DBServer with IP 192.168.1.3
On DBServer I have the database EMSMVC in the DBSERVER\SQLEXPRESS instance. The database is working.
On the AppServer in web.config I have:
<add name="DefaultConnection"
connectionString="Data Source=;Initial Catalog=EMSMVC;Integrated Security=True;Server=192.168.1.3;user id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
<add name="EMSMVCEntities"
connectionString="metadata=res://*/Models.EMSModel.csdl|res://*/Models.EMSModel.ssdl|res://*/Models.EMSModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DBSERVER\SQLEXPRESS;initial catalog=EMSMVC;integrated security=True;Server=192.168.1.3;user id=admin;password=DBSERVER\admin;multipleactiveresultsets=True;application name=EntityFramework""
providerName="System.Data.EntityClient" />
When I browse the app in the AppServer I get the following error:
[SqlException (0x80131904): Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.]
However, I'm not trying to connect using Anonymous logon.
Your connection string is flawed with several problems:
<add name="DefaultConnection"
connectionString="Data Source=;Initial Catalog=EMSMVC;Integrated Security=True;Server=192.168.1.3;user id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
You have both a Data Source (with no value) and a Server - you should use one or the other - but not both. Both basically mean the same thing - you neither of them is specifying the \SQLEXPRESS instance name ....
You're specifying an User Id (and password) in the connection string - but also Integrated Security=True, which means use the built-in Windows authorization - again: if you want to use User Id; then you must NOT also specify Integrated Security at the same time - this setting will take precedence over the specified User Id.
So your connection string should really be:
<add name="DefaultConnection"
connectionString="Data Source=DBSERVER\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
or using the IP address instead of the machine name:
<add name="DefaultConnection"
connectionString="Data Source=192.168.1.3\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
or if you prefer the Server= instead of the Data Source= setting:
<add name="DefaultConnection"
connectionString="Server=192.168.1.3\SQLEXPRESS;Initial Catalog=EMSMVC;User id=DBSERVER\admin;password=admin"
providerName="System.Data.SqlClient" />
I have my web.config like this:
<connectionStrings>
<add name="myConnectionString"
connectionString="Data Source=PC1;
Initial Catalog=BD1;
Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
<add name="myConnectionString2"
connectionString="Data Source=PC2;
Initial Catalog=BD2;
Integrated Security=False;
User Id=usuario;
Password=pass"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I can connect to the first one, a database with my windows user auth, but i can not to the second one, a database with other windows user auth.
Error: Login failed for user 'usuario'.
I can run Sql Server as other user, and i can connect to the database.
Picture how i run SQL server
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
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
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