I have been using "(LocalDB)\MSSQLLocalDB" as my database, and because I don't know SQL commands, I used "Linq to SQL Classes" to connect to the database and tables.
Now its the problem, I'm just using "Linq to SQL" to connect to the database and the "(LocalDB)\MSSQLLocalDB" authentication is set to "Windows Authentication", and because of that, I cannot run the application on another PC. it will give me this error:
Cannot open database "C:\USERS\******.MDF" requested by the login. The login failed.
Login failed for user 'blah\blah'
I tried to change the authentication mode to the "SQL Server Authentication" but it won't accept any username password and will show this error:
The attempt to attach to the database failed with the following information: login failed for user 'blah'.
What should I do to run my application on other PCs without worrying about the authentication, Can I just remove the authentication completely?
you just have to ensure that the windows accounts on both machines are members of the same group, and that group has the appropriate permissions. For example, if both accounts are Local Administrators, then you can use that group
Instead of "(LocalDb)" use the actual machine name of your computer. It looks from the error message that on the other computer it is looking for a copy of the local SQL Server engine but not finding it.
Using the server name instead of LocalDb will make it look for the other computer's copy of SQL Server and connect there.
Related
I've been trying to connect my Visual basic to SQL because this is what we are taught off but when I execute it, it shows this. How do I fix this?
This Windows user needs to be granted access to SQL Server and that specific database. It is usually configured during installation process of SQL Server. You can still do it by opening SSMS and adding this user under Security -> Logins node from Object Explorer panel.
Of course, to be able to do above, you need to connect to your SQL Server Express first. You may need to use another Windows user or a SQL Server user. The latter would be possible only if SQL Server Authentication has been enabled during installation process by choosing Mixed Mode for authentication (Windows + SQL Server).
You need to get full permission in SQL Server.
Open SSMS there is a Security folder then => Logins.
In Logins you will find your PC's username which is connected to Sql service
Right-click on your username => Properties
Check Windows Authentication Mode
I have a C# project with SQL Server 2008 R2 and the project runs with no problem on my local machine and when I publish it to the server Win2008 R2. But the project doesn't work and can't connect to the server with no error. All the database setting check and I enabled TCP/IP setting and etc. But still not worked. I think the problem is with connection string that is below.
When pages going to connect to the database, nothing happened in browser and browser stick in loading mode (waiting for respond).
Connection string on my computer
Data Source =(Local);Initial Catalog=Bulk;Integrated Security=True;Timeout=0;Max Pool Size=5000;
Connection string on Windows server
Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;Initial Catalog=Bulk;User ID=administrator;Password=My Windows Login Pass;Timeout=0;Max Pool Size=5000;
I got this error:
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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified
In your connection string of Server you have:
Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;
To connect via IP Address and Port of 1433 and over TCP/IP protocol
Initial Catalog=Bulk;
Bulk is your database name
User ID=administrator;Password=My Windows Login Pass;
Authenticate via SQL Server connection by administrator login user and its password.
I think your problem is in third part that you want to connect to SQL Server by your Windows user name; You can see valid logins of your SQL Server in Security branch of your registered server in SQL Server Management Studio that will shows your Windows user name like Domain Name\User Name so you need to change User Id to that.
Configure the Windows Firewall to Allow SQL Server Access. open port 1433 in windows firewall.
see this link. Or this.
Please Try to connect in your local Sqlserver With Live Login Detail,
If you are Success Then There should be Permission Need to set From the Live Hosting Server
if is it possible then please add the More specification.
You should log the errors that occur, e.g. in Application_Error if it's actually an ASP.Net project.
Using the log you should get errormessages that hint you or enable you to give more details so nobody has to guess what your actual issue is.
Regarding your issue:
Did you give your Windows account the necessary READ/WRITE access on SQL Server?
On MS SQL Server the account needs access to:
1. Be added to the general Security/Logins for an actual match of Windows account to Login.
2. Be added to the specific database Security/Users tab with the necessary database role membership.
In addition to specifiying your Windows account + password in the connectionstring: maybe it's better to run the application pool using a service-account and use
Integrated Security=True
and remove
User ID=administrator;Password=My Windows Login Pass;
I have changed my connection string to this and problem solved.
public static string ConnectionString = "Data Source=My Ip,1433;Initial Catalog=My DataBase;UID=sa;Pwd=My Pass;Timeout=0;Max Pool Size=5000;";
In sql server management studio
Click "Security" => "Logins" => "sa" right-click and click properties
in the left side click "Status" and in the right side,Choose enable in login
I have a c sharp application in one server and sql server database on different server. When I try to run bulk insert through C Sharp application, I am getting
"Cannot bulk load because the file operating system error code 5
(Access is denied)"
When i tried the same in sql server on the database server manually, it worked for windows authentication but not for sql authentication.
What should I do in order to make sql authentication work. Please help.
The SQL Server uses security profile of SQL Server service account to access the file if SQL Server authentication was used. OTOH with windows authenticatin, the authenticated windows account must have acces to the file. That's why it worked for you in one case and not in the other one. Give SQL Server service account access to the file.
The other point here is delegation. See this article for the explanation (and a remedy):
http://blogs.msdn.com/b/dataaccesstechnologies/archive/2010/10/29/sql-bulk-copy-error-operating-system-error-code-5-access-is-denied.aspx
To resolve this error, use SQL Server Authentication and specify a SQL Server login that uses the security profile of the SQL Server process account, or configure Windows to enable security account delegation.
Plese go through these references also BulkInsert ,SecurityAccountDelegation
Hope this will help.
I am connecting to two remote databases (sql server and the databases are on the same remote machine). Both databases are in separate directories.
I checked the security settings in the SQL management console for both databases and they are the same. However, I can connect to one database remotely (using a remote connection string in my C# application) but the other database gives me "Login failed - Login failed for user XXX/ZZZ".
Any ideas why this is happening? (Could it be related to the permissions on the physical directories where the files of the database are located)?
In SQL management console, check both Logins on the server and Users on each database.
It is a login issue as stated by the error. Make sure you can get to both databases uses SSMS using the logins that the C# application is using. If this works, then it is something else.
One common problem is not changing the default database from [master] or adding the user with rights to the database you want to query.
I'm writing Windows Service in C# and inside of it I'm unable to connect to the database.
This is the question I've asked recently:
SqlException: Cannot open database "path\db.mdf" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'
What I've done so far:
1) In server properties set flag "Identity verification with Sql Server and Windows"
2) Created login for sql server. Added user to the database with that login.
3) Added all available roles to this login.
Part 1:
If I connect to the server using Sql Server 2012 Identity Verification and than trying to attach database that is in some folder I get:
CREATE FILE encountered operating system error 5(Access is denied.)
while attempting to open or create the physical file 'path\db.mdf'.
(Microsoft SQL Server, error: 5123)
But I can attach the database if it's in this folder:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA
That's in SSMS.
Part 2:
What do I get when trying to attach database from Visual Studio 2012:
The attempt to attach to the database failed with the following information:
Login failed for user test_user
If I use this connection string in my code:
<add name="ConnectionName"
connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;
provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\v11.0;
attachdbfilename="path\db.mdf";
connect timeout=30;
User Id=test_user;Password=1;
MultipleActiveResultSets=True;
App=EntityFramework'"
providerName="System.Data.EntityClient" />
I get from my Windows Service app (written in C#) the following exception:
EntityException: The underlying provider failed on open.
Inner excetion: SqlException: Login failed for user test_user.
I'm sure I typed the login properly. I get this error whether the database is in MSSQL\DATA folder or not.
There is something wrong with the permissions to access some folders on my computer, but I don't know why, I've given this user all the permissions!
Also, one time after computer restart the windows service started properly and was able to connect to the database, but after some time it lost this ability. And I don't know why.
Please help, I'm struggling with this issue for the last 4 days. Thanks!
If you are writing an application you have to decide how to handle security.
There are two solutions for security in SQL Server.
1 - AD Security - Is SQL Server going to handle it via AD? the make sure the connection string uses trusted security. Make sure to add the employees AD account as a login/user and set the default database to the application one, not master. See my article on crafting databases.
http://craftydba.com/?p=656
2 - Standard Security - If the application is going to handle it, you need to use standard security. Create an application account (login/user).
Next, create an internal user table with different security levels. You will want to use application roles to enforce the different security levels.
Overall, you might want to look into using schema to separate and secure database objects.
http://craftydba.com/?p=1532
It looks like you have some reading and home work to do ...