can not open database on localnetworks - c#

I write a win app,and i create my database on the server by codes.now every client on local network can't login to my database and this error occured
:"cannot open database "test" requested by the login.the login failed for user "farzane".
the connectionstring for to make my database is:
ConnectionString=#"Data Source=SERVER\SQLEXPRESS;Initial Catalog=master;Integrated security=SSPI;Persist Security Info=False";
and it's my connection string for open my database:
ConnectionString=#"Data Source=SERVER\SQLEXPRESS;Initial Catalog=test;Integrated security=SSPI;Persist Security Info=False";
how can give permission for logining to my database to any client with codes???
thanks in advance for any help.

I would check two things here:
Ensure that your SQL Express install allows remote connections. (Simple to check using SQL Server Studio Manager).
You are using trusted authentication in your connection string. You have to explicitly give users on your domain access on the database. You will have to this in SQL Server.

are you using a domain for the network ?
if yes then make sure that the user name has access to the SQL server
if you're using a workgroup then it won't work... just create a user on the sql server and use the sql server auth at the server and connection string

Points i concluded:
First of all the users who are going to create the database , must be authorized to use master database. So ask your admin to allow permission to farzanne.
If you(farzanne) are admin, set farzanne to create databases permission to true. Or the other users that might create dbs. Also, if you allow all users then it will be difficult to handle, your application, so be alert.
What is the need of the dynamically createing database from application. Is this a part of setup or deployment or you are creating an isolated space that is different user different database.

Related

Error: the underlying provider failed on open. system.data.sqlclient.sqlexception login failed for user

After deploying my C# win app in client computer, the following error occurs:
The underlying provider failed on open.system.data.sqlclient.sqlexception
login failed for user. cannot open database "EmdadKhordo" Requested by the login
This is my connection string:
metadata=res://*/Models.EmdadKhodroDB.csdl|res://*/Models.EmdadKhodroDB.ssdl|res://*/Models.EmdadKhodroDB.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=EmdadKhodroDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
I use Entity Framework to access a SQL Server database.
Based on the cannot access database error message, authentication succeeded to the SQL instance but the specified database cannot be accessed. This may be because the EmdadKhodroDB database does not exist, is not online, or (most likely) inaccessible under the current security context. Make sure the account you are using has access to the database and the needed object permissions.
The DCL below will add the user to the database. You will also need to grant object level permissions directly to the user or a role of which the user belongs.
USE EmdadKhodroDB;
CREATE USER [YourDomain\YourAccount];
You can also manage your Windows user rights using SQL Management Studio. Just follow instructions from here for creating a new login and also configure mappings to each database you need access to.
Basically you need to make sure that your login is properly defined (Security -> Logins) and that it has the appropriate rights on EmdadKhordo database (read, write etc.). The recommendation is to allow the minimum required rights (e.g. do not allow to alter tables, if only SELECT, INSERT, UPDATE, DELETE statements are performed by the user).

Connect c# to a SQL Server in different domain

I have an c# app that tries to connect to a SQL Server that is in the same network but out of domain. I'm trying to use SqlConnection (I would prefer not use ODBC or ole db).
My code is the follow:
con.ConnectionString =
"Server=PCX\\SQL;"+
"Initial Catalog=BBDD_SinGuid;"+
"User id=\\\\PCX\\user;"+
"Password=passwordofuser;";
And I'm sure that the user and the password are correct and are allow to connect to the SQL Server. The error that throws is a fail in the login with the user \PCX\user.
I'm missing something?
you need to add trusted connectioon here..
Provider=SQLNCLI10;Server=myServerName\theInstanceName;Database=myDataBase;
Trusted_Connection=yes;
for more information you check below link it's has lot's of suggestion may be you will get your answer.
http://www.connectionstrings.com/sql-server-2008/

Domain considerations when using trusted_connection in SQL Server connection string

I have been trying to understand what using trusted_connection=true in a SQL Server connection string (from within C#) means. I understand that it uses the current Windows user credentials to connect to the database. But does it mean the database server and the current user can be in different domains, same domain or in different but trusted domains ?
trusted_connection=true means Integrated Security=SSPI;
If this is not present in connection string then you need to specify userid and password in connection string as:
server=yourservername;database=yourdatabase;user id=YourUserID;password=password
If any of two (Trusted_Connection=true or Integrated Security=true/SSPI) is present , then the Windows credentials of the current user are used to authenticate against SQL Server and any useriD=userid and password=password text will be ignored.
Whichever number of users may present and fromwhichever user you may have logged in, it will ignore the stuff if:
Trusted_Connection=true

Can't access database, access denied for user

I got this error message while connecting my app with the database at my website.
If i try using XAMPP using my computer, its work well.
FYI, the username and password is same as username and password that i created using XAMPP.
and also grant the privileges.
this is the connection string. for example the server is 174.125.80.140, the database name is myDB, the Uid is alfred, and the password is Alfred111.
MySqlConnection conn = new MySqlConnection("Server=174.125.80.140; Database=myDB;Uid=alfred;Pwd=Alfred111;");
I'm using MySQL client version: 4.1.22.
I'm still can't access the database. is there any solution??
If you are using MySQL workbench,
1) Start the workbench
2) click on the option "Users and Privileges" under SECURITY
3) click on add user (for the specific user), this is more secure because it lets you handle who has access over your database and lets you control access.
however if you want to grant access a large number of users for an application like c# application, then hard-code the username and password in the application, from the user privileges that you have set above.
Hope this helps (^_^)
Yes, you may have supplied the user and password correctly but have you configure the server (new server) to accept Uid=alfred;Pwd=Alfred111;?
Adding User in MySQL Server
If your app is on a different host that the MySQL server then you most likely need to add a new user granting permission for that host. Your alfred user is probably allowed by localhost and nothing else. Try CREATE USER 'altred#'%' identified by 'password'; and then grant that user privileges on myDB.
You can replace % with a specific IP address or hostname as well, % allows the connection from any host which is not necessarily safe.
You can try the following query to see the allowed user/host combos:
SELECT `User`, `Host` FROM `mysql.user`
Hope that helps.

login failed error for my database on localnetwork

I created my database on the server using code. Now no client on the local network can login to my database. This error occurs:
:"cannot open database "test" requested by the login.
the login failed for user "farzane".
Here is the connection string for my database:
ConnectionString=#"Data Source=SERVER\SQLEXPRESS;Initial Catalog=test;
Integrated security=SSPI;Persist Security Info=False";
How can I fix this problem?
I have about 30 clients on my network, and I don't want to create a login for every one. Is it possible to assign permissions and read/write access for all of them using code?
thanks.
If your clients have existing accounts on your LAN, you can right-click on the database, select Properties and then the Permissions section to assign users and groups the permissions you want them to have on your database. Alternatively, you can go to Security/Logins and right-click the groups or users you want to assign permissions to, select Properties, then choose the User Mappings section to grant permissions on specific databases.
Because you can do it with the GUI, you must be able to do it in code, but that I am afraid is not my area of expertise.

Categories

Resources