Failed login for user - sql

I'm developing a website for sharepoint using asp.net, it is connected to a database. In visual studio server explorer, the database is accessible using a new sql user I created. I granted sysadmin permissions to that user. However, when I deploy the site and run it, it gives me this error 'login failed for user'.
The sql server is configured to allow mixed authentications. I restarted the server, I played with the user permissions but nothing ever changed.
The connection string I got it from server explorer which I'm sure it is correct:
Data Source=servertest;Initial Catalog=qDB;User ID=me2;Password=***********"
What should I do? I've tried every possible solution I found on google and I ended up here.

Try like this by editing your connection string:-
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

I too had same scenario this worked for me
<connectionStrings>
<add name="connectionstring" connectionString="Data Source=XYZ\SHAREPOINT;Initial Catalog=DBName;Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>

You can Use connection string like this
<appSettings>
<add key="KhadamatConnectionString"
value="Server=[copy name from Your ServerName of SSMS];Database=AcaService;uid=admin;pwd=mypass;" />
</appSettings>
or
<connectionStrings>
<add name="KhadamatConnectionString" connectionString="Data Source=[copy name from Your ServerName of SSMS];Initial Catalog=AcaService;User ID=admin;Password=mypass;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Related

VB.net app doesn't update the connection string after changing the app.config file

I have done a windows application using vb.net and have set the connection string to be read from the app.config file. everything works fine, but when I try to change the connection string in the app.config file ( for example to change the database location) the application can't find the database anymore.
is there a problem or am I missing something related the connection strings. thank you
If you use MS Access database, you have to specify every database.
`<connectionStrings>`
<add name="ConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\DatabaseName1.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
</connectionStrings>
<connectionStrings>
<add name="ConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DatabaseName2.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
Also, there is a specific path to every database. The best way is to use the asp.net database folder App_Data and put all databases in this folder.

Unable to login with user that I created in sql database

I'm trying to connect with my DB using a account that I created with db_owner rights. Windows authentication works but not sql server authentication
I can confirm that the role was created as there is a error message login failed for user when using a wrong password. Compared to when correct password.
My local db is created in ASP.net web application by simply adding a local db in App data.
Error message is
user guest does not have permission to run DBCC checkpriamry file.
User has been created using
CREATE LOGIN [SomeUser] WITH PASSWORD = 'topsecret';
CREATE USER [SomeUser] FOR LOGIN [SomeUser];
exec sp_addrolemember 'db_owner', 'SomeUser'
EDIT:
<connectionStrings>
<add name="Shop" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Shop.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
https://imgur.com/a/9aCWVCU
are the links of error message
Your connection string when define login must be like this :
<connectionStrings>
<add name="Shop" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Shop.mdf;Initial Catalog=Shop.mdf;Persist Security Info=True; User ID=SomeUser; Password=topsecret;"
providerName="System.Data.SqlClient" />
</connectionStrings>

Database shows up in App_Data & not in SQL Server

Does anyone know why my database won't show up in SQL Server, but will show up in App_Data? I did code first migration and update the database but still can't see it. Please help
I try changing the connection and it did not work
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Rentals.mdf;Initial Catalog=aspnet-Rentals;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
No database shows up

Uploading Website with Visual Basic Inbuilt .mdf Database in VB.Net (Aspx)

I am creating a website to have a database with it (i.e. Upload the website with the App_Data folder that has Database.mdf in it).
But it cannot connect the attached database using (web.config file)
It works on localhost but it does not work when uploaded, can anyone help me?
**
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</connectionStrings>
<appSettings>
<add key="ConnectionString" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</appSettings>
**
The attribute 'Data Source' in ConnectionString notifies SQL Server instance you are using. On Localhost, it will work fine because you have a actual SQL service running there. But when you upload the Site to web server, you must have a SQL server instance running there.
To achieve that, you have to upload your database to server, then you will get server username, password. Now change the connectionstring according to that in web.config and your application will work fine. No need to keep .mdf in App_Data folder.

Can't connect to database when database has user and password

I am developing mvc 4 projects and when I use the following connection string it works:
<add name="name"
connectionString="Server=.\sqlexpress;Database=dbname;
Trusted_Connection=true;"
providerName="System.Data.SqlClient"/>
But when I add a username and password to this project, I can't connect to my database. I added the user credentials correctly. I have db_owner permission for this database, and in my database everything is correct. The connection string below does not work:
<add name="DocContext"
connectionString="Server=.\sqlexpress;Database=DocContext;
User ID=pooria;Password=19216801;Trusted_Connection=false;"
providerName="System.Data.SqlClient"/>
Connection String You are using follows format -
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
User ID=myDomain\myUsername;Password=myPassword;
Try using IP Address, Port in Data Source field like -
<connectionStrings>
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=190.190.200.100,1433;
Initial Catalog=MyDatabaseName;
Integrated Security=False;
User ID=MyUserID;Password=MyPassword;
MultipleActiveResultSets=True" />
</connectionStrings>
And the following link may help you
LINK