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/
Related
I have two desktop clients with VS 2017. I inherited a C# .NET app that connects to a SQL Server in the next room. We generally use SQL Server authentication (as opposed to Windows authentication) when we perform SQL queries.
I use a connection string that looks something like this ...
"Data Source=DR101; User Id = DR_DATA; Password = CD7504st; Integrated Security=SSPI; TransparentNetworkIPResolution=False"
... which works like a charm from the first desktop. From the second desktop it always fails to access the database, giving an error indicating a Windows login failure ...
... threw an exception.
System.Data.SqlClient.SqlException: Login failed for user 'SDAR\SdarAutoSvc'
I have compared everything I can think of between these two systems. As far as I can ascertain, they are identical in most every way ... both use the same Visual Studio (Help > About, and compared the long list of module versions. Identical on both systems), the same System.Data.dll module, the same App.config, C# source code, input data, etc.
The failing system only fails via this visual studio app - i.e., I can reach the database server from that desktop via SMSS, using the SQL Server credentials (not Windows authentication).
I am out of ideas as to how this second machine might be unable to access the database, and why it apparently uses Windows auth rather than the sql userId/password from the connection string.
If you want SQL server Authentication then remove Integrated Security=SSPI; from the connection string.
Try with this connection string -
"Data Source=DR101; User Id = DR_DATA; Password = CD7504st; TransparentNetworkIPResolution=False"
Im trying to connect to MySQL database on Azure through C#. I am using MySQLConnector package for my program.
I have admin account so I can easily access to the database through Sever Explorer in Visual Studio in SSH Sever Authentication . However I can not do the same with C#. I even tried to copy the exact connection string given by Sever Explorer but I still cant connect to my database through C# . I always get the error "1042: Unable to connect to any of the specified MySQL hosts." . The connection String from Sever Explorer provide necessary param : Data Source, Inital Catalog, Persist Security Info, User ID and Password.
As I have admin account. I have also tried to copy the connection String provided from Azure Portal for ADO.net. The connection String look a bit different . For example it provide extra parameter like
TrustServerCertificate, Encrypt, MultipleActiveResultSets. However if I used this connection string, the program does not compile. Visual Studio tell me the these parameters are not supported . For example :'Option 'MultipleActiveResultSets' not supported.' etc. If I deleted those paratemters, I have the same 1042 error. Please help me, I am new. Thanks
The Connection String from Sever Explorer in Visual Studio look like this:
Data Source= ******.database.windows.net;Initial Catalog=******;Persist Security Info=True;User ID=******;Password=******
The Connection String from Azure Portal look like this:
Server=tcp:******.database.windows.net,1433;Initial Catalog=******;Persist Security Info=False;User ID=******;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
The Connection String from Azure Portal look like this:
Server=tcp:******.database.windows.net,1433;Initial Catalog=******;Persist Security Info=False;User ID=******;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
This is a SQL Server connection string. You cannot use MySqlConnector with this connection string. Are you sure you're using Azure Database for MySQL and copying the connection string from the right database?
I am trying to connect to a SQL Server instance via a .NET Winforms client. When I use a "Trusted connection" connection string all works fine, yet when I use a standard security connection string I get an error that the login fails.
The really confusing thing is that in the database both the Windows authentication user and the SQL Server authentication user have the exact same permissions. For testing I made both part of the "sysadmin" role.
I have got to be missing something simple but I have checked username and password over and over yet it still fails. Has anyone else run into this?
This works ...
string connectionString = #"server=dbserver.myhost.com\myinstance;database=MyDB;integrated Security=SSPI;";
This does not work ...
string connectionString = #"server=dbserver.myhost.com\myinstance;database=MyDB;User Id=testuser;Password=mypassword;";
I'm trying to access my SQL Server Express database, but every time I try, I receive this message:
Login failed for this user.
Here is the code:
sqlConnection cs = sqlConnection("Data Source=.\\SQLEXPRESS;
Initial Catalog=MyDatabase#4; Integrated Security=TRUE");
cs.Open();
MessageBox.Show(cs.State.ToString());
cs.Close();
How can I fix this problem?
Try to write your computer name instead of . after "Data Source". For example:
Data Source=Michael-PC\\SQLEXPRESS;Initial Catalog=MyDatabase#4;Integrated Security=True";
The SQL is not able to authenticate your windows user because it may have no access rights on the database... Try using an administrator account or to use a SQL Server privileged account.
What I sometimes do is get Visual Studio to connect, via the Server Explorer, and then copy and paste the connection string from there. If you have SQL Management Studio Express, that will work too.
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.