See all databases from SQL connection string [duplicate] - c#

This question already has answers here:
C# connect to database and list the databases [duplicate]
(6 answers)
Closed 8 years ago.
I have 3 databases attached to my SQL instance. From my application the C# connection string is:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = #"Data Source=server\SQLEXPRESS;Initial Catalog=Database1;Integrated Security=True";
Mr problem is my SQL scripts reference the other attached databases and some of my scripts are based on a dynamic USE statement to look at a different attached database.
Is there anyway to make the connection string see all attached databases so my SQL scripts I run through the connection string can query other databases besides the specified initial Catalog database?
Thank you

I suggest you add all connection strings in config file and call them as needed.

Related

C# MySQL MySqlConnection connectionstring for empty password [duplicate]

This question already has an answer here:
What may cause the KeyNotFoundException when trying to open a MySQL connection
(1 answer)
Closed 2 years ago.
I am trying to connect C# and database MySQL : using MySql.Data.MySqlClient;
My codes are as below. I am getting error. I think it is because of empty password.
string connstring = #"server=localhost;userid=root;password=;database=client";
MySqlConnection dbcon = new MySqlConnection(connstring);
if you don't want to expose the password in connect string. you can use the Windows authentication instead.
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/authentication-in-sql-server

How to connect to a distant mysql database using asp.net [duplicate]

This question already has answers here:
Connecting to a mySQL database using asp.net
(2 answers)
Closed 6 years ago.
I want to connect to a disant mysql database wich is located in another server using Asp.net C#.
How can i did it ?
Thanks.
You need this code:
var myConnectionString = "server=127.0.0.1;uid=root;pwd=12345;database=test;";
var conn = new MySqlConnection(myConnectionString);
conn.Open();
Also you need the public IP of the MySql server and the correct credentials (userid, password and database name).

Invalid connection string [duplicate]

This question already has an answer here:
SQL Server connection string
(1 answer)
Closed 6 years ago.
Apparently this connection string is incorrect?
connectionString="Server=mydb.com:1433/sqlExpress;Database=d;User Id=d;Password=pw;"
the first think that I see is that you have type wrong this part
Server=mydb.com:1433
use
Server=mydb.com,1433
the sql server use the comma to separate the port.
Also take a look at that answer: Setting up connection string in ASP.NET to SQL SERVER

c# sql connection through internet [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I was wondering if can I connect to sql database from another computer without installing sql server (is this possible). I am creating a c# wpf program that would get and insert data in sql database that is placed in my PC, in all computers where this program is installed using internet. Should I use in connection string my internet IP, or what, because I’m confused?
My connection string
String connString = #"Network Library=dbmssocn;
Network Address=127.0.0.1,1433;
Integrated security=SSPI;
Initial Catalog=db";
Also i forgot to say that i'm new in programing area, and i want to connect to sql database through lan connection
Assuming that your remote database (on your other computer) accepts remote connections, you can accomplish this via a traditional ADO.NET connection or you could use an ORM like Entity Framework to handle the connection.
You can see an example below that takes advantage of the SqlConnection class which does exactly what it's name implies :
using(var sqlConnection = new SqlConnection("Your Connection String"))
{
var query = "Your Query";
using(var sqlCommand = new SqlCommand(query,sqlConnection))
{
sqlConnection.Open();
// Execute your query here using sqlCommand.ExecuteNonQuery()
// or some other execution method
}
}
You would just need to ensure that your actual connection string to target your remote database is correct.
Yes, it is possible. You could use ADO.NET or Entity Framework to accomplish this goal. However, I would recommend setting up a web api on the sever you have hosting the database, which you could call to get/post data. I personally wouldn't hard code any connection strings in the program you plan to deploy to end user workstations. Just call the web api and let your web api talk to the database.

Connection pooling in Entity Framework 1 [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Entity Framework and Connection Pooling
Does EF1 support Connection Pooling? If yes, what we need to do to manage it?
I don't think you need to do anything except to make sure your connection string throughout the application stays the same. .NET will take care of the rest herself.
Connection pooling is supported by EF and it is default. If you want to change it you can alter Pooling parameter in the connection string true or false.
Assuming SQL Server, somewhere underneath the EF code, a SqlConnection is created using a connection string. A pool of connections will be created per connection string.
It should simply work, without any code / config on your side

Categories