sqlconnection

Is it important to Open a sql connection in the transactionscope

笑着哭i 提交于 2019-12-05 05:16:55
I created a sqlconnection, CN1. Then this CN1 is opened. Later in the code there is a transactionscope. If I execute a sql command on this CN1 connection, is this within transaction? Code looks like this; SqlConnection cn1 = new SqlConnection(); cn1.Open(); //connection opened when there is no ambient transaction. ... using(TransactionScope scope = new TransactionScope()) { SqlCommand cmd; //a typical sql command. ... cmd.ExecuteNonQuery(); //Is this command within transaction? ... } It is a MUST to open the connection within the TransactionScope to ensure that the connection is enrolled in

Powerbuilder 12.5 database connection beginner tutorials

南笙酒味 提交于 2019-12-04 18:39:08
I am fairly new to powerbuilder 12.5 and i cant find much tutorials on database management on SQL 2008. I need to connect to it via code like in VB.NET vs2008 Dim con As New SqlConnection Con.connectionstring = "Data Source=servername;Initial Catalog=user;Integrated Security=True" I need to select, insert, update and delete data... Any help on code samples Datawindows Most database work with PB is done using datawindows. After you create a new datawindow, you set up your select statement in it. Then you add a datawindow control to your form and set the control to use the datawindow that you

Is this Sql-injection-proof Asp.net code?

谁说我不能喝 提交于 2019-12-04 12:13:34
Problem: I have a form with text values, and a function that must return a string query based on the values of the text values too. Solution: I created a SQLCommand query with parameters, then I put the SQLCommand.CommandText to a string and I returned it (to the business logic that is going to handle the query) Main Question: Is it sql-injection proof? Code Example: sQuery = "select * from xy where x like '%@txtNameParameter%'"; SqlCommand cmd = new SqlCommand(sQuery); cmd.Parameters.Add("@txtNameParameter", SqlDbType.VarChar); cmd.Parameters["@txtNameParameter"].Value = txtName.Text; string

calling new SqlConnection() hangs program

家住魔仙堡 提交于 2019-12-04 06:17:08
This one has me stumped. I'm not even trying to connect to a database. When this code gets to the line where I instantiate a new SqlConnection object, it just hangs there, not throwing an exception or anything. I've tried compiling it for 2.0. 3.5 and 4.0, and they all hang. Of course it works on my machine and yours, too. But I'm trying to run this code on a Windows Server 2008 x64 server, and it won't budge. // example.cs using System; using System.Data; using System.Data.SqlClient; public class MainClass { public static void Main(string[] args) { Console.WriteLine("start"); SqlConnection

What is the relationship between open SqlConnections in the client app and processes in SQL Server?

纵然是瞬间 提交于 2019-12-04 04:21:33
问题 I just tried to make a simple schema change to a table in a SQL Server database (by using the Design tool in SMSS). Whenever I tried to save the change, it kept timing out. I wondered whether this was due to existing connnections which were 'locking' the table. I decided to kill connections as an experiment. I queried master..sysprocesses to get the current spids for that database, and killed them one by one until I was able to save my schema change. (Not very scientific, but I'm far from an

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

让人想犯罪 __ 提交于 2019-12-04 04:00: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? 回答1: 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

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:37:19
问题 I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command = new SqlCommand(); // dostuff } Obviously it does matter if you plan to run more than one command with the same connection, since closing an SqlDataReader is more efficient than closing and

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

≡放荡痞女 提交于 2019-12-04 03:04:06
问题 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

C# DbConnection cast to SqlConnection

耗尽温柔 提交于 2019-12-03 23:31:49
问题 I found this piece of code in one application Database database = DatabaseFactory.CreateDatabase("connection string"); DbConnection connection = database.CreateConnection(); connection.Open(); SqlConnection sqlConnection = (SqlConnection)connection; Is it safe, SqlConnection derieve from DbConnection. Database comes from Microsoft.Practices.EnterpriseLibrary.Data. According to documentation CreteDatabase returns DbConnection. 回答1: No it is not safe, casting is never safe and it may blow

Call dll function from sql stored procedure using the current connection

早过忘川 提交于 2019-12-03 23:09:59
问题 Can I call a dll from a stored procedure using the open connection? I have a dll that gets data from SQL Server and I don't want to open a new connection when I call it from the stored procedure. Thank you Here is an exemple public class Class1 { public static SqlString GetName(SqlString str) { SqlCommand cmd = new SqlCommand(str.ToString()); cmd.CommandType = System.Data.CommandType.Text; string name = cmd.ExecuteScalar().ToString(); return name; } } and this is the SQL code CREATE FUNCTION