I can't connect via ASP.NET to a named instance of a sql server, that itsn't the default instance.
My servername is NAMEOFSERVER\NAMEOFINSTANCE.
If I try to connect to the default instance of the server, it works.
I use the following connection string:
connection_string = "Data Source=" + servername + ";Initial Catalog=" + db_catalog + ";User Id=" + user + ";Password=" + password + ";persist security info=False;Trusted_Connection=No;Connection Timeout=1000"
The SQL Server Browser service is running.
Make sure your connection string have the pattern above:
var connectionString = $"Data Source=myServerName\\myInstanceName;Database=myDataBase;User Id=myUsername; Password=myPassword;",
Also, make sure you can connect via SQL Management Studio, since instances of the SQL Server can limit access to some users (make sure you connect to the same user name + password you want your app to use).
EDIT
If the user you are using to connect is not part of a Windows account, please open your instances security configuration and make sure Mixed Mode is enabled.
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/change-server-authentication-mode
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/authentication-in-sql-server
You might want to check if your variable "servername" contains a double backslash. This is needed because backslash is a escape character.
connection_string = "Data Source=" + servername.Replace("\\", "\\\\") + ";Initial Catalog=" + db_catalog + ";User Id=" + user + ";Password=" + password + ";persist security info=False;Trusted_Connection=No;Connection Timeout=1000"
Related
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'localhost' (using password: NO)
I need to connect my database to the report viewer in visual studios however this error always appears and i dont know what changes i have to make...the password was already set to 'root' however this error still appears, I want to know what "(password: NO)" means since this only appeared when i accidentally flushed out the privaleges.
Password NO just means that you don't pass over a password.
Are you connecting like this:
string connsqlstring = "SERVER=" + server + ";PORT=" + port + ";user=" + user + ";password=" + password + ";database=" + databank;
sqlconn = new MySqlConnection(connsqlstring);
sqlconn.Open();
Or how are you doing it ?
Another thing is, i had problems before with Root and made a new User with which i now connect.
Maybe that helps.
Cheers,
Frozen :)
I have a stand alone application that works great with a Local user account in MS SQL. When I try to use an active directory service account instead I appear to be running into problems.
It appears Microsoft want's the exe to run as the domain user service account which is not an option for me. Looking at alternatives, one person mentioned having main exe launching a second exe that does the work or having a local windows service.. neither of these are an option either. It feels like this is getting more complex then it needs to be.
Here is an example of the piece of code I am working with:
private void MakeConnection(){
string ServerNM = #"MyServer";
string Database = #"Test01";
string Username = #"testdomain\testuser";
string Password = #"testpass";
string connection_string = "Server=" + ServerNM
+ "; Database=" + Database
+ "; User ID=" + Username
+ "; Password=" + Password
+ "; Max Pool Size= 1000;";
try {
SqlConnection oSqlConnectionTest = new SqlConnection(connection_string);
oSqlConnectionTest.Open();
}catch(Exception oException){
MessageBox.Show("Error: " + oException.ToString());
}
}
Is this a real limitation or am I missing something?
SQL Server does not accept domain accounts in the connection string for security reasons.
So I have a client program and a database on sql server that's on my pc (localdb). I'm trying to set connection on, but it seems like provider is wrong. My connection string looks like this:
connection.ConnectionString =
"Data Source=(localdb)\\Projects;" +
"Provider=MSIDXS;" +
"Initial Catalog=TermPaperWork;" +
"User id=DAZZBOURGH\\Dazzbourgh;" +
"Integrated Security=True;" +
"Password=;";
So everything is OK there, except provider. I don't get what it is and how to use it and how to know which provider suits my database.
How do I find out my provider for exact base?
I always use http://www.connectionstrings.com when I have questions on the format of a connection string.
I am trying to connect my app, developed in C# with a SQL Server database.
The program is done! It's a mobile app.
My database is on C:\ProgramFiles\MyAppName\MyDatabase.sdf
My code line is:
SqlConnection conn = new SqlConnection("server =" + iP.Text +"," + port.Text + ";integrated security=false;Initial Catalog=" + DB.Text + ";User ID=" + userName.Text + ";Password=" + Pass.Text + ";Trusted_Connection=False;");
iP.Text = my IP (102.168.XXX.XXX)
port.Text = 49214 or 1433
DB.Text = "MyDatabase.sdf"
userName.Text= "sa"
pass.Text= "MyPass"
But when I try to connect it, the app says:
er.Message = "El servidor SQL Server no existe o se ha denegado el acceso.
My server name is the same that my userName?
The application was made by someone else, I did nothing. But now I have to change some things and make it better. There is no manual
Any idea? I really don't know what to do
You are using Sql Server Compact Edition (SDF file) not Sql Server.
The classes needed to connect to this kind of database are different
SqlCeConnection conn = new SqlCeConnection(......)
The classes for Sql Server cannot parse correctly your connection string and you get the mentioned error. Of course, the classes for Sql Compact Edition require a reference to the appropriate DLL
System.Data.SqlServerCe.dll
and the appropriate using statement at the beginning of your code file
using System.Data.SqlServerCe;
As last note, the connection string for a SQL CE database is simply
"Data Source = MyDatabase.sdf; Password ='<pwd>'"
doesn't seem possible to pass a specific user. See connectionstrings.com
I have the following code to determine a SQL Server database's compatibility level:
Microsoft.SqlServer.Management.Smo.Server server = new Server(myServerName);
if (!server.Databases.Contains(database))
{ throw new ArgumentException("Specified database ('" + myDBName+ "') not found on '" + myServerName + "'"); }
string connstr = string.Format("Data Source={0};" +
"Persist Security Info=False;" +
"User ID={1};" +
"Password={2};Enlist=False;", myServerName, username, password);
server.ConnectionContext.ConnectionString = connstr;
Microsoft.SqlServer.Management.Smo.Database db = server.Databases[myDBName];
DataSet ds = db.ExecuteWithResults(#"select compatibility_level
from sys.databases where name=db_name()");
I have two users, one of which is able to run this code and get the proper value back. Another user runs this code connecting to the same Server/Database with the exact same credentials and the DataSet returned contains no rows.
What could possibly be the difference between the two users that would cause one to get no result back for the same query? Is there a better way to get Database compatibility?
By the way, this code runs/works on SQL Server 2005 through 2012.
Edit: I should have pointed out that myServerName, myDBName, username, and password are always the same--the only difference is the two different Windows users running the code.
I suspect that the user who returns results has the VIEW_ANY_DEFINITON permission granted to his login. Grant this permission to the other user and he should get the results back.