Any one help me out in making a string. i want to connect with local database, my local db has no password. I m using below string to connect with database but getting error unable to open connection for user
string _connectionString = "Data Source=(local);Initial Catalog=CRM;Integrated Security=False;User Id=Ali-Pc;Password= ? ;connection Timeout=0";
You don't mention what you're trying to connect to, but this site is very useful for finding
the connection strings to most databases
Connection Strings
You probably want integrated security set to true and no password
Related
I can log into the server explorer to work on my database.
Yet I fail to access it with a Connection String.
is your connection string in the format of Server=tcp:{server}.database.windows.net,1433;Initial Catalog={databaseName};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
double check the password and firewall for your IP
This is ADO.NET Connection String that I use for my Azure SQL C# project:
Server=tcp:YOUR_SERVER,1433;
Initial Catalog=YOUR_DB_NAMR;
Persist Security Info=False;
User ID=YOUR_LOGIN;Password=YOUR_PASSWORD};
MultipleActiveResultSets=False;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;
And as #Krunal mentioned, double check your login credentials
and make sure your IP is whitelisted on the server side.
You can set a 0.0.0.0 to 250.250.250.250 range as a whitelisted range, for testing purposes.
With the service running on my machine(Setup on a LAN with no internet connection), I can connect with the following :
string sConnection = #"Server=localhost; Port=3306; Database=some_database; Uid=root; Pwd=genericpassword;";
MySqlConnection cnTest = new MySqlConnection(sConnection);
cnTest.Open();
How should I Modify my connection string to connect from another PC on the lan to my MYSQL server?
*side note : The IP of my local machine is setup to be 192.168.0.1.
What goes after "Server=" is the address of the server.
So if your server is on 192.168.0.1 - it'll look like
string sConnection = #"Server=192.168.0.1; Port=3306; Database=some_database; Uid=root; Pwd=genericpassword;";
Just replace 'localhost' with the address you're given.
That said, it's generally considered to be good procedure to store connection strings in web.config / app.config - whenever you deploy it on some other environment, you won't want to rebuild it. This link might help with that.
What should be the proper structure of Connection string in C# to access SQL Server 2008 R2 over internet using the public ip of the server ?
I used the below connection string . It works fine within our network using local IP but when i am trying to acces it over internet with public IP, I am getting error.
SqlConnection con = new SqlConnection("Data Source=tcp:192.168.0.16,49582;Initial Catalog=TrulyDB;uid=sa;pwd=sa#pass123;");
There are different ways to Create Connection String which depends on
Authentication type as you know
1.> Windows Authentication
2.> SQL Server Authentication
Follow this link
SqlConnection con = new SqlConnection("Data Source=192.168.0.16,49582;Network Library=DBMSSOCN;Initial Catalog=TrulyDB;uid=sa;pwd=sa#pass123;");
I am trying to create a simple login page in ASP.NET C# but am getting some error.
I googled about the error, and tried all the solutions but to no avail.
What am I doing wrong? The error is:
"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)"
I think it's something to do with my connection string which is as follows:
<add name="cn"
connectionString="server=HCL;DataBase=GS;Integrated Security=True" />
"HCL" is another machine connected to my PC through the LAN and this database, "GS", resides on it. Is the problem with the value I am giving in "Server" attribute of the above code? If not what else may I be doing wrong?
I can tell all solutions I tried. Let me know if that's required.
I don't think "Server" is a valid property for a connection string. Try "Data Source" instead. "Integrated Security" should also be set to SSPI:
<add name="cn" connectionString="Data Source=HCL;Initial Catalog=GS;Integrated Security=SSPI"/>
UPDATE:
I just noticed that you have also used "Database". This should be "Initial Catalog".
UPDATE2:
There is a neat trick for creating connection strings by using .udl files. If you create an empty file called "something.udl" and double click it, Windows will open a nice dialog for defining connections. To create a connection string for a SQL Server, choose "Microsoft OLEDB Provider for SQL Server" on the "Provider" tab and then fill in your server name, login credentials, and database name on the "Connection" tab. Finish by testing the connection and click "OK".
After the dialog is closed, you can drag the .udl file into Notepad or Visual Studio and you will see that the .udl file actually contains a connection string ready for you to use (note that if you wish to use the connection string with SqlConnection in .NET you must remove the "Provider=SQLOLEDB.1" part of the string).
The error is definitely connectivity. Usually in firewall rules, remote connections disabled or just general connectivity issues.
However using integrated security is probably your issue. If you are in a domain/workgroup this could work,w ith properly set permissions, but if not then you probably need to pass your credentials. Integrated security will pass the credentials of your logged in account and is the normal method if the database in on the same PC as the application.
<add name="cn" connectionString="Data Source=HCL;Initial Catalog=GS;User Id=YOURSQLUSERNAME;Password=YOURSQLPASSWORD;"/>
See http://www.connectionstrings.com/ for more connection string examples.
Try adding "Integrated Security=SSPI;" or specify your UID, Pwd for connecting to the server. You might be getting struck at the authentication.
Open management studio and connect with SQL Server using SQL Server Authentication. Enter userId and password to connect. Use that userid and password in your connection string.
connectionString="Data Source=HCL;Initial Catalog=GS;User Id=UserId;Password=password;
User Id -> UserId you want to login
using. like 'sa'
Password -> password of you user.
If you get error Login failed for user" 'yourusername' then this link will help. This is to enable user sa.
SQL Server 2005 "Login failed for user" sa
EDIT:
connectionString="Data Source=HCL;Initial Catalog=GS;Persist Security Info=True;User ID=sa;Password=pass"
This link might help
sql-network-interfaces-error-26-error-locating-server-instance-specified
I think you should try trusted_connection = true instead of integrated security in your connectionstring.
See here: http://connectionstrings.com/sql-server-2005
Second reason could be that you have several instances of your database which you have to write into the connectionstring.
When trying to connect to a .mdf databse in ASP.NET (using c#) I am given 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)
Does this mean my connection string is wrong? What should it be?
Aside from that, I am very new to ASP.NET. I am trying to connect to this database in the same way I would in c# normally (using data adapters and SqlCommands). Is this the right way to go about it, or is there a different way? When I started a new website adding user accounts worked (there was a wizard or something?) but I couldn't work out how to add more user information. What is the best way to connect to an SQL database and add user accounts with login and personal details in ASP.NET?
EDIT: My Connection String is data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Users.mdf;User Instance=true
If I read your connection string properly, you're never specifying a database to use!
data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|\Users.mdf;User Instance=true
Add the database to the connection string - and also, loose the extra backslash after the |DataDirectory|:
server=.\SQLEXPRESS;database=YourDatabase;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|Users.mdf;User Instance=true
OK, I've fixed it. For reference for anyone else:
The correct connection string was given in the Web.config file.
The connection string I needed was Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Users.mdf;Integrated Security=True;User Instance=True