sqlconnection

How do I change a sql server password that has expired from C# code?

两盒软妹~` 提交于 2019-12-01 19:52:48
When you are using a SqlConnection to connect to a MS Sql Server, if the password has expired you will get a SqlException Number: 18487 or 18488. How can you change the user's password in code during the connection attempt? Use the static SqlConnection.ChangePassword() method. string original_dsn = "server=mysql.server.com,1433;database=pubdb;User Id={0};Password={1};" string dsn = String.Format(original_dsn, username, password); SqlConnection conn = new SqlConnection( dsn ); try { conn.Open(); } catch(SqlException e) { if (e.Number == 18487 || e.Number == 18488) SqlConnection.ChangePassword

MySQL “network-related or instance-specific error occurred while establishing a connection to SQL Server”

假如想象 提交于 2019-12-01 18:49:21
I've been looking around for a solution to this issue and the only one that might provide a solution is the only one I haven't tried, because it involves changing system properties. I want to avoid that if I can. The Connection string is correct, but it still won't connect. The exception occurs on line 30, which is where the connection string is opened. conn.Open() Here is the Code: using System.Text; using System.Data.SqlClient; namespace My_Sql_Program { class Program { static void Main() { try { // Step 1: Create a SqlConnection Object to connect to the // SQL Northwind database.

Azure Web Api - Waiting Sql Connection every 4 minutes and 30 minutes

社会主义新天地 提交于 2019-12-01 16:52:10
问题 Within a request on an ApiController, I'm tracking the duration of awaiting the Sql Connection to open. await t.TrackDependencyAsync(async() => { await sqlConnection.OpenAsync(); return true; }, "WaitingSqlConnection"); If my request is not called for at least 5 minutes, then any new call will see the duration of OpenAsync be huge (c. 3s) instead of immediate. I'd like to understand the reason to eradicate that crazy slowness. UPDATE I created an endpoint just to open the SqlConnection . If I

ExecuteReader requires an open and available Connection. The connection's current state is closed

≯℡__Kan透↙ 提交于 2019-12-01 16:25:21
Ok, I asked about this very error earlier this week and had some very helpful answers and without doubt things have drastically improved since I started following the suggestions. However, now I am using the 'correct', best practice method to access the database I still get this error on some functions and I cannot get it to disappear for that block. Here is my code: Public Shared Function doesBasketExist(ByVal baskethash As String) As Boolean Dim _r As Boolean Using db As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("pitstopConnectionString").ConnectionString)

How bad is opening and closing a SQL connection for several times? What is the exact effect?

北慕城南 提交于 2019-12-01 08:38:43
For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open and close the connection unless the connection state is already open before the method call. What I want to know is how does unnecessarily opening and closing SQLConnections affect the performance of the application. How much does it need to scale to see the bad

How bad is opening and closing a SQL connection for several times? What is the exact effect?

匆匆过客 提交于 2019-12-01 07:20:47
问题 For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open and close the connection unless the connection state is already open before the method call. What I want to know is how does unnecessarily opening and closing

SqlConnection Singleton

大憨熊 提交于 2019-12-01 06:52:58
Greetings, I would like to ask if creating Singleton to have only one active connection to db is a good idea. What i would like to do is: 1) I have a wcf service 2) wcf service gets data from db 3) i would like to create a singleton like this to have only one connection to db: private static PersistanceSingleton _Instance; public static PersistanceSingleton Instance { get { if (_Instance == null) { _Instance = new PersistanceSingleton(); } return _Instance; } } I know this is not an ideal singleton but i just wrote it for this post purpose. I would like to have some persistance repositories

How To Access Azure Function App ConnectionString Using dotnet Standard

我怕爱的太早我们不能终老 提交于 2019-12-01 05:50:45
My Azure Function App has a ConnectionString defined. I want to retrieve it from a C# function written in dotnet standard 2.0. I have tried adding System.Configuration.ConfigurationManager to the project.json and using var str = ConfigurationManager.ConnectionStrings["my string"].ConnectionString; but I get the error run.csx(24,15): error CS0103: The name 'ConfigurationManager' does not exist in the current context How do I access the connection string? Crazy Crab ConfigurationManager is not available in Azure Functions v2 .NET Standard projects. Azure FUnction v2 now uses ASPNET Core

SqlConnection Singleton

白昼怎懂夜的黑 提交于 2019-12-01 05:30:54
问题 Greetings, I would like to ask if creating Singleton to have only one active connection to db is a good idea. What i would like to do is: 1) I have a wcf service 2) wcf service gets data from db 3) i would like to create a singleton like this to have only one connection to db: private static PersistanceSingleton _Instance; public static PersistanceSingleton Instance { get { if (_Instance == null) { _Instance = new PersistanceSingleton(); } return _Instance; } } I know this is not an ideal

Most efficient way to test SQL connection string availibility

久未见 提交于 2019-12-01 03:06:32
I have this code down which I tried to make it Test SQL string connectivity, but I dont know how to handle the part with connection.Open = true would you please help me to solve this out? Thank you so much for your time. private void button1_Click(object sender, EventArgs e) { try { using (SqlConnection connection = new SqlConnection("Data Source='" + textBox1.Text + "';Initial Catalog='" + textBox2.Text + "';User ID='" + textBox3.Text + "';Password='" + textBox4.Text + "'")) { try { connection.Open(); if (connection.Open == true) // if connection.Open was successful { MessageBox.Show("You