sqlconnection

SQL Server Azure “Login failed for User”

久未见 提交于 2019-12-11 03:47:08
问题 I am using the following code to perform SQL commands to my azure DB. The I do two calls inside my ASP.NET MVC action method. One to delete from Table A, and the second call to delete from Table B. using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnectionString)) { using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand()) { conn.Open(); command.CommandText = statement; command.ExecuteNonQuery(); } } For whatever reason when I make the

work with an already open database connection

佐手、 提交于 2019-12-11 03:05:52
问题 This is a little wierd, but I want to check if connection to my database is already open or not? How do I check that? and if open I want to be able to work with it straightaway without going through all the statements: sqlconnection conn = new sqlconnection("string ..."); Can this be done? I know the connection string and the connection name too. I want to check if this connection is available first and then proceed. 回答1: If you know the connection string then the easiest way of obtaining a

Will pooled SQL Connections be scavenged if there is still a reference to them?

﹥>﹥吖頭↗ 提交于 2019-12-10 23:26:31
问题 @usr and I are having a disagreement in another question about whether or not .NET will scavenge open connections that have been idle, but still maintain a held reference. I maintain, based on documentation, that if the physical connection is idle for a period of time, it will be reclaimed after a period of time even if a SQLConnection object reference remains held. usr claims that this won't happen, and it only reclaims connections that no longer have references. His assertion as this would

Obtaining SQL connection most efficiently when using ASP.NET and web services

[亡魂溺海] 提交于 2019-12-10 19:06:26
问题 When using web services (we're specifically using asmx and WCF) with ASP.NET, what is the best way to establish a SQL connection? Right now, I'm establishing a new connection for each web service call, but I'm not convinced this will be too efficient when there will be thousands of users connecting. Any insight on this topic would be much appreciated. 回答1: What you are doing is fairly standard. Assuming you are using the same connection string, the connections will be coming from the

ConnectionTimeout not working

血红的双手。 提交于 2019-12-10 16:59:53
问题 I try to build a database failover (ASP classic) but I have problem with the setting: ConnectionTimeout. I set it to 1 second but still the server try to connect to the first connection for more then 20 second. I like the connection will be lost after 1 second so I can transfer the user to the second connection right a way. Thanks, <% DSN = "Provider=SQLOLEDB; Data Source=62.62.62.62; Initial Catalog=150109;User Id=noa; Password=tfdh545h54h;" DSN1 = "Provider=SQLOLEDB; Data Source=127.0.0.1;

How to test SqlServer connection without opening a database

前提是你 提交于 2019-12-10 14:57:48
问题 The title pretty much says it all. I want to create a SqlConnection and then check that connection without opening a database, cause at that point I don't know yet where will I connect to. Is it possible to do that? The SqlConnection class has a 'Open' member which tries to open the database you'd set in the Database property, and if you didn't set one, SqlServer tries with the master db. The thing is the user I'm trying to connect with (MACHINE\ASPNET) has access to some databases (which I

Overhead of creating new SqlConnection in c#

倖福魔咒の 提交于 2019-12-10 14:52:22
问题 A while back I wrote an ORM layer for my .net app where all database rows are represented by a subclass of DatabaseRecord . There are a number of methods like Load() , Save() etc. In my initial implementation I created a connection to the DB in the constructor of DatabaseRecord e.g. connection = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionName"].ConnectionString ); I then call Open() and Close() on that SqlConnection at the beginning and end of my methods which access

Impersonation: ASP.Net MVC Controller Action vs. Web Forms

霸气de小男生 提交于 2019-12-10 14:34:44
问题 Is there a difference with impersonation between an ASP.Net MVC controller actions vs. an ASP.Net Web Form? Using the exact same code within the same web project, I am able to successfully impersonate the Windows user when connecting to SQL Server from a Web Form but not from the Controller Action. Here is the code sample I am testing from each: string sqlQuery = @"SELECT Top 10 FullName FROM Customer"; // Connect to the database server. You must use Windows Authentication; SqlConnection

When should I close the db connection?

血红的双手。 提交于 2019-12-10 14:23:58
问题 Is it a must to close the connection in PHP script? 回答1: Depending on the configuration of your DB server, there is a limit on the possible number of connections opened to it at the same time. So, if your script : does some queries and, then, does some long calculations without doing any query anymore It can be interesting to close the connection after having done all your queries -- and to only open the connection when it's becoming needed. Still, note that connections are closed when the

Does SqlDataAdapter close the SqlConnection after Fill() function?

眉间皱痕 提交于 2019-12-10 02:58:52
问题 Does SqlDataAdapter close the SqlConnection after the Fill() function or do I need close it myself? string cnStr = @"Data Source=TEST;Initial Catalog=Suite;Persist Security Info=True;User ID=app;Password=Immmmmm"; cn = new SqlConnection(cnStr); SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Date", cn); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds); cn.Close() // ???????? Console.WriteLine(ds.Tables[0].Rows.Count); Console.WriteLine(cn