.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
ASPEvil
david stephan
Santhakumar Munuswamy
Fauzul Azmi
Post New Web Links

Alternatives for SqlConnection()

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
 
Hello ...I am using databases in my project.I always use SqlConnection() To open a connection then use the connection to interact database.But I have heard somewhere that opening SQLconnection() take a time.  and if on different pages of projects I repeatedly Connect database then It will take long access time always....So I want to know that if there is any other methods which don't use the SQLConnection to interact database and increase the response time of database...


View Complete Post


More Related Resource Links

Data Points: LINQ Projection Queries and Alternatives in WCF Services

  

LINQ's ability to project randomly shaped data into anonymous types can be a blessing and a source of frustration, says Julie Lerman. It's great when you just need to grab a special view of your data, but it can be problematic in certain circumstances. She explains what the limitations are and how to get around them.

Julie Lerman

MSDN Magazine May 2010


'SqlConnection' Error

  
Within the button code (Default.aspx.vb), there is an undefined 'SqlConnection.' What is the cause of this error? Go to the following URL link, download the 'High Res' Visual Studio snapshots at: http://cforedu.com/snap.pdf The button code written in VB code reads as follows:Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Public Function strLong(ByVal pstrText As String) As String '''/ Extract just the 0-9 chars from a string Dim strTemp As String = Nothing Dim lngI As Long = 0 strTemp = "" For lngI = 1 To Strings.Len(pstrText) If Strings.InStr(1, "1234567890", Strings.Mid(pstrText, lngI, 1)) > 0 Then strTemp = strTemp & Strings.Mid(pstrText, lngI, 1) End If Next Return Strings.Left(strTemp, 20) End Function ' strLong Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlapplicationConnectionString").ToString()) Try Dim cmd As SqlCommand = conn.CreateCommand() cmd.CommandText = "INSERT INTO Application (" & " First, Last, City, State)"

'SqlConnection' Error

  
Within the button code (Default.aspx.vb), there is an undefined 'SqlConnection.' What is the cause of this error? Go to the following URL link, download the 'High Res' Visual Studio snapshots at: http://cforedu.com/snap.pdf The button code is written in VB code and reads as follows: Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Public Function strLong(ByVal pstrText As String) As String '''/ Extract just the 0-9 chars from a string Dim strTemp As String = Nothing Dim lngI As Long = 0 strTemp = "" For lngI = 1 To Strings.Len(pstrText) If Strings.InStr(1, "1234567890", Strings.Mid(pstrText, lngI, 1)) > 0 Then strTemp = strTemp & Strings.Mid(pstrText, lngI, 1) End If Next Return Strings.Left(strTemp, 20) End Function ' strLong Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlapplicationConnectionString").ToString()) Try Dim cmd As SqlCommand = conn.CreateCommand() cmd.CommandText = "INSERT INTO Application (" & " First, Last, City, State)" & ") VALUES (" & " @First, @Last, @City, @State" cmd.P

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.

  
 Hi all,When i run my project on my own computer, it works fine. But when i deploy it to server, it gives me this error. I can run my other dts and sp, but i get this error on this.. The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. I googled it but could not find a solution. How can i solve this problem? 

How to just define connection string, sqlconnection and sqlcommand once and use it over and over..

  
I'm curious if there is a way to in the web.config. or somewhere else, to set up "the basics" for executiting various sql queries and stored procedures throughout a website, with out having to keep identitifying the connectionstring, sql connection, command, etc.   I'm thinking back to my old ColdFusion days, where you would declare all this in the application.cfm, and then it was quickly and easily reused without needing to retype the info.   Any suggestions/samples on doing this in VS 2010?   

Declaring the SqlConnection and SqlCommand objects in a webform without CodeBehind

  
Declaring the SqlConnection and SqlCommand objects in a webform without CodeBehindI am trying to query data from a MS SQL server with a C# web form without "CodeBehind". I want to write the information to a table in the web form's body.I am having trouble declaring the SqlConnection and SqlCommand objects that connect to the server.How do you use "using System;", "using System.Data;", "using System.Data.SqlClient" inside the script element of an .ASPX file?I know how to do it with JavaScript and ADO. (code below)---------------------------------------------------------------------------------------------------<html><head><table><%@ language="javascript" %><%var sqlstr = " ";var conn_str = " ";var AdOpenForwardOnly = 0;var adLockReadOnly = 1;var rs = new ActiveXObject("ADODB.Recordset");var conn = new ActiveXObject("ADODB.Connection");conn_str = "PROVIDER=SQLOLEDB;Server=my_server;" +"Database=db_myDatabase;User ID=myUserID;" +"Password=myPassword;"sqlstr = "SELECT * FROM [myTable]";conn.open(conn_str, "", "");rs.open(sqlstr, conn, AdOpenForwardOnly, adLockReadOnly);while(!rs.eof){Response.write("<tr><td>" + rs(0));Response.write("</td><td>"+ rs(1));Response.write("</td><td>"+ rs

How does SqlConnection manages IsolationLevel?

  

This MSDN article states that:

An isolation level has connection-wide scope, and once set for a connection with the SET TRANSACTION ISOLATION LEVEL statement, it remains in effect until the connection is closed or another isolation level is set. When a connection is closed and returned to the pool, the isolation level from the last SET TRANSACTION ISOLATION LEVEL statement is retained. Subsequent connections reusing a pooled connection use the isolation level that was in effect at the time the connection is pooled.

The SqlConnection class has no member that may hold the isolation level. So how does a connection know what isolation level to run in???

The reason I'm asking this is because of the following scenario:

  1. I opened a transaction using TransactionScope in Serializable mode, say "T1".
  2. Opened a connection for T1.
  3. T1 is finished/disposed, connection goes back to connection pool.
  4. Called another query on same connection (after getting it from connection pool) and this query runs in serializable mode!!!

Problem:

  1. How does the pooled

ClientViaBehavior URI Alternatives

  

Hello

I am looking for way to not require a client to use the ClientViaBehavior. I have built a routing service and do not want have to provide the client the address manually.

Any ideas would be appreciated.

Thanks


Trusted_Connection=false is not working in Sqlconnection

  

Hi,

I am not sure if this is the right place to post this problem.

Briefly I have a custom Sqlconnection string in my infopath 2010 form which is:

SqlConnection

 

con = new SqlConnection("Server=SQL2;Database=Payroll;User ID=xxxx;Password=xxxxxxx;Persist Security Info=false;Trusted_Connection=false");

Trusted_Connection=false indicates that it uses user ID and Password from the string to connect to the MS SQL database.

System.Data.SqlClient.SqlConnection'

  

Hello

Please look at the error given below

'System.Data.SqlClient.SqlConnection' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using directive or an assembly reference?)


Code which directing me error

using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class Display_Image_IO : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSource = fetchImages();
        GridView1.DataBind();
    }

    public DataTable fetchImages()
    {
        SqlConnection da = new SqlConnection(GetConnectionSt

Disposing a SqlConnection (ADO.NET)

  

Hello guys,

I had a question relating to the disposal of a SQL connection. I have some code that checks whether a certain database is present on a SQL Server instance. This code is being called in an installer, so what I actually want it to do is ensure that there isn't already a database on the server with the same name than the one that will be created in the installer. If such a database exists, the user will be notified so that he can remove the database manually, and then click OK or something to let the installer proceed. I extracted the relevant piece of code. This snippet can be used in a console application to reproduce the problem:

static void Main(string[] args)
{
	try
	{
 		string connectionString = "Data Source=.;Initial Catalog=MyDatabase;User Id=MyUser;Password=MyPassword;";

		using (SqlConnection connection = new SqlConnection(connectionString))
		{
			connection.Open();
			connection.Close();
			//connection.Dispose();
		}

		Console.WriteLine(

Where should I keep SQLConnection object ?

  

Hello,

What's the best place to keep database connection object like SQLConnection or ISession if I can choose only Application, Session or Items objects. And why ?

Thanks in advance.


SqlConnection Error

  

Hi,
I have recently changing my coding in my program to use SqlConnection. Previously I was connecting to SQL Server database using ODBC connection.

            public void Connect()
            {
                  try
                  {
                        connection = new SqlConnection("Data Source=10.100.11.41,4848;Initial Catalog=XXXXDB;User Id=XXXUser;Password=xxxxx;");
                        connection.Open();
                        command.Connection = connection;
                  }
                  catch (Exception ex

'SqlConnection' is not defined

  

'SqlConnection' is not defined in the behind code as follows:

 

 

Source Error:

Line 22:         ' we don't need to explicitly dispose the object in the code, 
Line 23:         ' the using statement takes care of it.
Line 24:         Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("subscriberConnectionString").ToString())
Line 25:             ' Create a DataSet object.
Line 26:             Dim dsMenu1 As New DataSet()


Source File: I:\Websites\CMP\Host\Fox Backup\Default.aspx.vb    Line: 24

Snippet reads as follows:

 

Imports System.Web.DynamicData


Partial Class _Default
    Inherits System.Web.UI.Page

        
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim visibleTables As System.Collections.IList = MetaModel.Default.VisibleTables
        If (visibleTables.Count = 0) Then
            Throw New InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax a" & _
        

sqlconnection

  

Hi, i would like to write a streaming programming which will keep updated or query the database. I would like to use a connection instead of open and close connection on each transaction. But the streaming programming would not end, running at all the time. So, is it any effect if i am using only one connection (within a long period). Such as performance, timeout issue, or others exception.


Alternatives to Sessions.

  

Hello All i have a situation where worker process recycling is causing session to expire and loose all the session data. Change to State Server and SQL server seems to be very complicated and impossible beacuse we use third party objects which are non-serializable.

We need to let users keep running our ship tracking website for weeks or months beacuse they use it in their lobby and they do not want to touch it again.

What alternatives i have if worker process recycles which causes to loose session data.

I will need to atleast retain their user id and password to autologin them incase session expires.

Any Suggestions?..

 

 

 

 

 


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend