SqlConnection Server Error

Dec 6, 2006

I am having a hard time finding information about this error
online.  I was hoping someone could help me with it.  I am working with
MS Visual Studio 2005.  The SQL Server version is 2000.  The error
bellow says I am trying to connect to SQL 2005.  Also, I can use MSVS
Server Explorer and SQL Server Enterprise Manager to connect to the
database.
Here is my code:
 
imports System.data
Dim Connect As New SqlClient.SqlConnection
Dim Adapter As New SqlClient.SqlDataAdapter
Dim St As New DataSet
Dim ConnectString As String
ConnectString = "Data Source=MANDB01;Initial Catalog=MANCON_WEB;Integrated Security=True"
Connect.ConnectionString = ConnectString
Adapter.SelectCommand = New SqlClient.SqlCommand("select * from item_cat1", Connect)
Adapter.SelectCommand.Connection.Open()
Adapter.Fill(St)
Connect.Close() 
 

The browser is reporting this error: 
An error has occurred while establishing a connection to
the server.  When connecting to SQL Server 2005, this failure may be
caused by the fact that under the default settings SQL Server does not
allow remote connections. (provider: Named Pipes Provider, error: 40 -
Could not open a connection to SQL Server)

View 3 Replies


ADVERTISEMENT

Please Help Me Error In Sqlconnection

Jan 4, 2008

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
this problem occured when i rum my program which contain database connection
any one there can help me please?

View 6 Replies View Related

Getting Error Type SqlConnection Is Not Defined...

Mar 10, 2008

I'm a noob to sql ce 3.5 and am getting the error "Type SqlConnection is not defined". I'm thinking this has something to do with the sql client not being installed but am not sure. I've tried adding - 'Imports System.Data.SqlClient' but it's not available, anyone ahave any ideas on how to fix this?

Thanks,

View 4 Replies View Related

Error:SqlConnection Does Not Support Parallel Transactions

Jul 17, 2006

This is my code in vb.net with Sql transactionI am using insertcommand and update command for executing the sqlqueryin consecutive transactions as follows.How can I achive parallel transactions in sql------------------start of code---------------------trybID = Convert.ToInt32(Session("batchID"))                    strSQL = ""                    strSQL = "Insert into sessiondelayed (batchid,ActualEndDate) values (" & bID & ",'" & Format(d1, "MM/dd/yyyy") & "')"
                    sqlCon = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("conString"))
                    Dim s1 As String = sqlCon.ConnectionString.ToString                    sqlDaEndDate = New System.Data.SqlClient.SqlDataAdapter("Select * from sessiondelayed", sqlCon)                    dsEndDate = New DataSet                    sqlDaEndDate.Fill(dsEndDate)
                    dbcommandBuilder = New SqlClient.SqlCommandBuilder(sqlDaEndDate)
                    'sqlCon.BeginTransaction()                    'sqlDaEndDate.InsertCommand.Transaction = tr                    If sqlCon.State = ConnectionState.Closed Then                        sqlCon.Open()                    End If                    sqlDaEndDate.InsertCommand = sqlCon.CreateCommand()                    tr = sqlCon.BeginTransaction(IsolationLevel.ReadCommitted)                    sqlDaEndDate.InsertCommand.Connection = sqlCon                    sqlDaEndDate.InsertCommand.Transaction = tr                    sqlDaEndDate.InsertCommand.CommandText = strSQL                    sqlDaEndDate.InsertCommand.CommandType = CommandType.Text
                    sqlDaEndDate.InsertCommand.ExecuteNonQuery()                    tr.Commit()                    sqlDaEndDate.Update(dsEndDate)                    sqlCon.Close()                End If            Catch es As Exception
                Dim s2 As String = es.Message                If sqlCon.State = ConnectionState.Closed Then                    sqlCon.Open()                End If                strSQL = " update SessionDelayed set ActualEndDate= '" & Format(d1, "MM/dd/yyyy") & "' where batchid=" & bID & ""                sqlDaEndDate.UpdateCommand = sqlCon.CreateCommand()                tr1 = sqlCon.BeginTransaction(IsolationLevel.ReadCommitted)                sqlDaEndDate.UpdateCommand.Connection = sqlCon                sqlDaEndDate.UpdateCommand.Transaction = tr1                sqlDaEndDate.UpdateCommand.CommandText = strSQL                sqlDaEndDate.UpdateCommand.CommandType = CommandType.Text                sqlDaEndDate.UpdateCommand.ExecuteNonQuery()                tr1.Commit()                sqlDaEndDate.Update(dsEndDate)                sqlCon.Close()
 
            End Try
'-------------End----------------

View 1 Replies View Related

SqlConnection Error( Unrecognized Escape Sequence )

Feb 16, 2008

 CSharp:SqlConnection Con = new SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True"); its give ErrorUnrecognized escape sequence 

View 12 Replies View Related

There Is Always An Error When I Want To Hardcode With SqlConnection. Pleas Help Me Check It.

Feb 14, 2006

I am currently using VWD. I only run my web applications with the Cassini. However, as long as I want to hardcode with SqlConnection object, an error occurs. I did a little bit modification to the following codes which use SqlConnection and was quoted from the book "Professional ASP.NET 2.0", Wrox. <%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Configuration" %> <script runat="server">         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)         If Not Page.IsPostBack Then             Dim MyConnection As SqlConnection             Dim MyCommand As SqlCommand             Dim MyReader As SqlDataReader             MyConnection = New SqlConnection()            MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDB").ConnectionString             MyCommand = New SqlCommand()            MyCommand.CommandText = "SELECT TOP 3 * FROM Paspnet_Users"             MyCommand.CommandType = CommandType.Text             MyCommand.Connection = MyConnection             MyCommand.Connection.Open()            MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)            gvCustomers.DataSource = MyReader             gvCustomers.DataBind()            MyCommand.Dispose()            MyConnection.Dispose()         End If     End Sub     </script> <html> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="gvCustomers" runat="server"> </asp:GridView> </div> </form> </body> </html> The error: System.NullReferenceException was unhandled by user code   Message="Object reference not set to an instance of an object."   Source="App_Web_v1u8yf_l"   StackTrace:        at ASP.sqlconnectiontest_aspx.Page_Load(Object sender, EventArgs e) in F:My DocumentMy StudySITMT4Introduction to ASP.NetMeowMeowShoppingCartSQLconnectionTest.aspx:line 13        at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)        at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)        at System.Web.UI.Control.OnLoad(EventArgs e)        at System.Web.UI.Control.LoadRecursive()        at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Please help me find out what's the problem. Thanks beforehand.

View 1 Replies View Related

Error 'Type 'SqlConnection' Is Not Defined' In VS2005/aspx.vb Files

Apr 17, 2008

 I defined the following connection string (strConn) and coded "Dim oConn As New SqlConnection(strConn)".In this VS 2005/ASP.net 2.0 program, 'SqlConnection' was underlined and showed 'Type SqlConnection is not defined' error. 
 What wrong with my VS 2005/ASPnet 2.0 coding, or SQL Server 2000 database configuration?
TIA,Jeffrey
connectionString="Data Source=webserver;Initial Catalog=Ssss;Persist Security Info=True;User ID=WWW;Password=wwwwwwww"providerName="System.Data.SqlClient"

View 3 Replies View Related

Server IP As Variable In SqlConnection?

Sep 25, 2007

I'm attempting to create an ASP page that generates a report from a user-selected table on a user-selected server. Is it possible to employ a variable to define the  "server=" attribute in the SqlConnection method, and what would the syntax be? Thanks. 

View 3 Replies View Related

SQL Server 2000 To SQL Server 2005 - Any Changes Required To Existing Code, System.Data.SqlClient.SqlConnection?

Dec 13, 2007

My web project (ASP.NET 2.0 / C#) runs against sql server 2000 and uses the System.Data.SqlClient.using System.Data.SqlClient;
 I use System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlCommand to make the connections to the database and do selects and updates.  Is it correct to continue to use these against SQL Server 2005?  I ask because I made a connection string (outside of .Net) for SqlServer 2005 using the SQL native provider and it had the following - Provider=SQLNCLI.1 and any connection strings I had made (also outside of ASP.NET) fro SQL Server all used Provider=SQLOLEDB.1.  This is why I wondered if there is a different SqlClient in .Net 2.0 for SQL Server 2005?
Cheers
Al

View 1 Replies View Related

SqlConnection Access Is Denied Exception With SQL Server 2005

Feb 21, 2006

Hi,I have a SqlConnection object with connection string, "Data Source=server1;Initial Catalog=CDCollection;User Id=joe;Password=11111."For User ID, I created a new user "joe" in the Management Studio.I tried to use this user, but sqlconnection threw an exception stating access was denied.I noticed that SQL Server 2005 has user accounts that you can create for the server and for the database, but I am confused by this.  How can a create a non-sa user account that I can give to the SQLConnection object that will work?  Do I need to create a user for the server and the same user for the database CDCollection?  I am not all familiar with SQL Server administration.Any help or leads would be appreciated.

View 3 Replies View Related

SQL SERVER 2005 + ASP.NET 2.0: Problems With Data.SqlClient.SqlConnection --&> Login Failed For User 'username'

Apr 23, 2007

I have lots of problems with the connection. I've connected many dropdownlists to the database and i didn't have problems at all. I also try an example of an ASP.NET book:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString= "<%$ ConnectionStrings:CIPPEC%>"
InsertCommand=
"INSERT INTO
[member] ([first_name], [last_name], [malefemale], [yearborn])
VALUES
(@first_name, @last_name, @malefemale, @yearborn)">
<InsertParameters>
<asp:FormParameter Name="first_name" Type="String"
FormField="FirstTextBox" />
<asp:FormParameter Name="last_name" Type="String"
FormField="LastTextbox"/>
<asp:FormParameter Name="malefemale" Type="Int32"
FormField="MFRadioButton" />
<asp:FormParameter Name="yearborn" Type="Int32"
FormField="YearDropDown" />
</InsertParameters>
</asp:SqlDataSource>
And it worked well.  But when i try to connect my page with:
Dim connect As New Data.SqlClient.SqlConnection( _
"Server=glgrand-arSQLEXPRESS;UID="WindowsStartupUser";password="WindowsStartupPass"; database=CIPPEC")
connect.Open()
Dim cmd As New Data.SqlClient.SqlCommand( _
"INSERT PRUEBA (PersonaJuridica, NombreRazonSocial, Nombre, Segundo_nombre, Apellido) " & _
"VALUES (txtPerJur, txtRazSoc, txtName, txtSecondName, txtApellido)", _
connect)
cmd.ExecuteNonQuery()
connect.Close()
The error message says: Login failed for user 'username'.
I tried lots of things but it didn't work:
In SQL Configuration Manager:
Client Protocols: TCP/IP and Named Pipes are enabled.
In SQL 2005 Services: Server Properties: Built-in Account: Local System
SQL Server Surface Area Configuration: Remote connections: Using both TCP/IP and Name Pipes connection is selected.
In SQL Management Studio i created a new login glgrand-ar/UserStartupName , with sysadmin server role and user mapping my CIPPEC database.
I don't know what else i could try, i tried it at home and at work and i couldn't connect to my database and make an INSERT. It stops at Connect.Open() with the error that i wrote in this subject message.
It's evident that i'm doing something wrong (because i'm new): Could you please help me with a solution and explain me what are the data that i have to put on the Data.SqlClient.SqlConnection ?? I'm using the Windows authentication: i'm putting my username and password and it doesn't worked.
Thank you!!

View 1 Replies View Related

SQL Server Management Studio Express:Cannot Access Destination Table ‘dbo.FromExcel’in SqlConnection-VBExpress Programming(P.1)

Oct 18, 2007

Hi all,
In the Object Explorer of my SQL Server 2005 Management Studio Express, I do not have €˜Northwind€™ Database installed yet. I executed the following source code (that was copied from a book) in my VB 2005 Express:
/////////////////////----Form9.vb----//////////////////////////
Imports System.Data.SqlClient
Imports System.Data
Public Class Form9

Dim cnn1 As New SqlConnection

Private Sub Form5_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'Compute top-level project folder and use it as a prefix for
'the primary data file
Dim int1 As Integer = InStr(My.Application.Info.DirectoryPath, "bin")
Dim strPath As String = Microsoft.VisualBasic.Left(My.Application.Info.DirectoryPath, int1 - 1)
Dim pdbfph As String = strPath & "northwnd.mdf"
Dim cst As String = "Data Source=.sqlexpress;" & _
"Integrated Security=SSPI;" & _
"AttachDBFileName=" & pdbfph
cnn1.ConnectionString = cst

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Create a command to create a table
Dim cmd1 As New SqlCommand
cmd1.CommandText = "CREATE TABLE FromExcel (" & _
"FirstName nvarchar(15), " & _
"LastName nvarchar(20), " & _
"PersonID int Not Null)"
cmd1.Connection = cnn1

'Invoke the command
Try
cnn1.Open()
cmd1.ExecuteNonQuery()
MessageBox.Show("Command succeeded.", "Outcome", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Create a command to drop a table
Dim cmd1 As New SqlCommand
cmd1.CommandText = "DROP TABLE FromExcel"
cmd1.Connection = cnn1

'Invoke the command
Try
cnn1.Open()
cmd1.ExecuteNonQuery()
MessageBox.Show("Command succeeded.", "Outcome", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click


'Declare FromExcel Data Table and RowForExcel DataRow
Dim FromExcel As New DataTable
Dim RowForExcel As DataRow

FromExcel.Columns.Add("FirstName", GetType(SqlTypes.SqlString))
FromExcel.Columns.Add("LastName", GetType(SqlTypes.SqlString))
FromExcel.Columns.Add("PersonID", GetType(SqlTypes.SqlInt32))

'Create TextFieldParser for CSV file from spreadsheet
Dim crd1 As Microsoft.VisualBasic.FileIO.TextFieldParser
Dim strPath As String = _
Microsoft.VisualBasic.Left( _
My.Application.Info.DirectoryPath, _
InStr(My.Application.Info.DirectoryPath, "bin") - 1)
crd1 = My.Computer.FileSystem.OpenTextFieldParser _
(My.Computer.FileSystem.CombinePath(strPath, "Book1.csv"))
crd1.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
crd1.Delimiters = New String() {","}

'Loop through rows of CSV file and populate
'RowForExcel DataRow for adding to FromExcel
'Rows collection
Dim currentRow As String()
Do Until crd1.EndOfData
Try
currentRow = crd1.ReadFields()
Dim currentField As String
Dim int1 As Integer = 1
RowForExcel = FromExcel.NewRow
For Each currentField In currentRow
Select Case int1
Case 1
RowForExcel("FirstName") = currentField
Case 2
RowForExcel("LastName") = currentField
Case 3
RowForExcel("PersonID") = CInt(currentField)
End Select
int1 += 1
Next
int1 = 1
FromExcel.Rows.Add(RowForExcel)
RowForExcel = FromExcel.NewRow
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
Loop
Try
cnn1.Open()
Using sqc1 As SqlBulkCopy = New SqlBulkCopy(cnn1)
sqc1.DestinationTableName = "dbo.FromExcel"
sqc1.WriteToServer(FromExcel)
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn1.Close()
End Try

'Read the FromExcel table and display results in
'a message box
Dim strQuery As String = "SELECT * " & _
"FROM dbo.FromExcel "
Dim str1 As String = ""

Dim cmd1 As New SqlCommand(strQuery, cnn1)
cnn1.Open()
Dim rdr1 As SqlDataReader
rdr1 = cmd1.ExecuteReader()
Try
While rdr1.Read()
str1 += rdr1.GetString(0) & ", " & _
rdr1.GetString(1) & ", " & _
rdr1.GetSqlInt32(2).ToString & ControlChars.CrLf
End While
Finally
rdr1.Close()
cnn1.Close()
End Try
MessageBox.Show(str1, "FromExcel")

End Sub

End Class
///////////////////////////////////////////////////////////////////////
This is Part 1 (The length of input exceeds 50000 characters). Part 2 will be posted in this site shortly.

View 4 Replies View Related

SqlCONNECTION

Jul 27, 2006

Public Conn As New SqlConnection("Data Source=localhost;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")Public Conn As New SqlConnection("Data Source=XX.XXX.XX.XXX;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")
This two commands are in my application.  I switch between the two so I can test my application.
When I put my application on the server, I use the localhost SQLCONNECTION.  The other is commented out.  However, the application continues to connect to the server with the address that is commented out.
THIS IS VERY FRUSTRATING...  HELP!!!!

View 1 Replies View Related

SqlConnection ???????

Oct 2, 2006

Hi, Someone can explain to me what happend in this situation...i have this and want to call a procedure with connection parameters protected void Button1_Click(object sender, EventArgs e)
{

SqlConnection edo = new SqlConnection();
edo.ConnectionString = "server=myserver; uid=admin; pwd=; " +
"database=name1";
SqlCommand com = edo.CreateCommand();
com.CommandType = CommandType.Text;
My_proc(edo, com);
}
protected void My_proc(SqlConnection edo , SqlCommand com)
{
try
{edo.Open();
}
catch{}
finally{ edo.close();}
}

Well what happend with the SqlCommand and SqlConnection when return to Button_Click() Are they alive? Can be used in Buton_Click like parameters for another procedure? or i have to create it again?Thx in advance..                 

View 1 Replies View Related

Sqlconnection

Oct 16, 2006

please help me !!!?I have a problem with sqlconnection definition when I add the sqlconnection from toolbox :like this: Imports System.Data.SqlClientPartial Class _Default    Inherits System.Web.UI.Page    Private Sub InitializeComponent()        Me.sqlConnection1 = New System.Data.SqlClient.SqlConnection        Me.sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"        Me.sqlConnection1.FireInfoMessageEventOnUserErrors = False    End Sub    Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If Not IsPostBack Then            Dim cmduniversity As SqlCommand            Dim dtruniversity As SqlDataReader            cmduniversity = New SqlCommand("select * from university", sqlConnection1)            sqlConnection1.Open()            dtruniversity = cmduniversity.ExecuteReader            dtruniversity.Close()            sqlConnection1.Close()        End If    End SubEnd Classin the sqlconnection.open the nullrefrence exception occures butwhen i define myself this exception dosn't occure.like this:   Imports System.Data.SqlClientPartial Class _Default    Inherits System.Web.UI.Page    Private Sub InitializeComponent()       End Sub    Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If Not IsPostBack Then            sqlConnection1 = New SqlConnection            sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"            sqlConnection1.FireInfoMessageEventOnUserErrors = False            Dim cmduniversity As SqlCommand            Dim dtruniversity As SqlDataReader            cmduniversity = New SqlCommand("select * from university", sqlConnection1)            sqlConnection1.Open()            dtruniversity = cmduniversity.ExecuteReader            dtruniversity.Close()            sqlConnection1.Close()        End If    End Subwhere is the problem?

View 2 Replies View Related

SqlConnection

Apr 28, 2007

 Can someone help me out? I am trying to establish a SQL server connection in my C# code. My C# code crasheds though. Can someone tell me what Iam doing wrong? Here is the C# code:
 
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["TheDividerConnectionString"]);
 Here is the connection string as defined in the web.config file:
 <connectionStrings>  <add name="TheDividerConnectionString" connectionString="Data Source=BVCOMPUTERSQLEXPRESS;Initial Catalog=TheDivider;Integrated Security=True"   providerName="System.Data.SqlClient" /> </connectionStrings>
 

View 21 Replies View Related

Sqlconnection

Jun 11, 2007

is their any code which can check my project for any connections which  are open and never closed.
frm 1.1,sql server 2000

View 1 Replies View Related

Sqlconnection

Jan 24, 2008

Would anyone ahve any ideas why when i debug this code, it stops and freezes at cn.open(); A raw sql query against the DB works in this format.
int top=10;SqlConnection cn = new SqlConnection("Data Source=blah;Initial Catalog=blah;Integrated Security=blah");
SqlCommand cmd = new SqlCommand("SELECT DISTINCT TOP (@nrows) [CustNu] FROM [Customer] WHERE [CustNu] like @term", cn);cmd.Parameters.AddWithValue("nrows", top);cmd.Parameters.AddWithValue("term", prefixText + "%");
 
List <string> suggestions = new List<string>();
cn.Open();

View 5 Replies View Related

Pb With SQLConnection

Mar 13, 2008

 HiI would like to have some help for my problem.I'm trying to retreive the connectionString "MyConnectionString" from app.config using method 1 or 2 to get a connection to my DB (without any success.) --> Partial codepublic SqlConnection GetConnection()        {            // reference to System.Configuration Library is done                   1    SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);--> thrown NullReferenceException on   Conn.Open();                   2    SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["MyConnectionString"]);--> thrown InvalidOperationException ConnectionString not initialised            return Connection;        }       public Contest GetContestFromDB()        {            SqlConnection Conn = GetConnection();            Conn.Open(); ->> thrown Exception 1 or 2...Here my app.config :<?xml version="1.0" encoding="utf-8"?><configuration>  <appSettings>    <clear/>    <add key="MyConnectionString" value="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMesdocumentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add>  </appSettings>  <connectionStrings>    <clear/>   --> using <clear/> to avoid to load from machine.config    <add name="MyConnectionString" connectionString="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMes documentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add>  </connectionStrings></configuration> I'm using Visual Studio 2008 with SQLServer 2005 Express Embedded and WindowsXP SP2 .Have you got any idea ?I'm not able to sleep anymore...And I've test this code in ASP.net with the same ConnectionString in the web.config file and it works !!I'm lost.By the way, thx if ou get an answer  ww4ss

View 2 Replies View Related

SQLConnection

Aug 24, 2004

Hi
I have the next simple code, what do i have to change to match it to SQL?
The code:
Sub Page_Load (Source As Object, E as EventArgs)
dim strConn as string =("Provider=" & "Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =C:webspacesegolforferaforfera.co.ildbguestbook.mdb")

Dim MySQL as string = "SELECT Name, EMail, URL, Comment FROM Guestbook"
Dim MyConn as New OleDBConnection (strConn)
Dim Cmd as New OleDBCommand (MySQL, MyConn)
MyConn.Open ()
rptGuestbook.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
rptGuestbook.DataBind()
End Sub
Thank's and have a good day.

View 3 Replies View Related

Dynamic Sqlconnection

Jul 17, 2006

I have a database for each of my customers and want to connect to a database depending on who is logged in.
all my users have their database name in the user profile.
how can i use the database name in the user profile to change the initial catalog to connect to aaother database?
 
thanks
 
 

View 6 Replies View Related

SqlConnection And Performance

Nov 16, 2006

Hi there,  I'm not sure if the way I handle SqlConnection in my apps is the most performant one.So my apps use db heavily and there are loads of classes with methods like 1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString))
2
3 {conn.Open();
4 // more code here
5 }
6
7
 As I use using the connection is closed and the object is disposed when leaving the code block.I know that the connection is taken from a pool and when closed it returns to the pool as though I'm not sure if it is better to have one "global" SqlConnection objectand to use that object for all classes or most of them. What about the ConfigurationManager, doesn't it slow down the performance as well when I'm accessing the ConnectionString value thousands of times?I hope someone can point out the issues.Many thanks in advance, Limbic

View 1 Replies View Related

Sqlconnection Object

Jan 3, 2007

I need some information on sqlconnnection object.  I see it referenced in some exercises, and also displayed in the toolbox on some articles, but I'm running .net 2.0 and I have no sqlconnection in my toolbox, but more importantly, I can not seem to drop the data connection from my database/server explorer to my form to create a sqlconn object.   When I highlight the data connection (in my case it's machinenamesqlexpress.pubs.dbo)  and try to drag it - it immediately goes to a NO icon (that is a circle with a slash thru it) and I can not drop it onto my form.  I can see the database with no problems in explorer.
 I have been able to create a sqlconnection programatically:
Dim sqldatasource1 As SqlConnection = New SqlConnection()
sqldatasource1.ConnectionString = "Data Source=localhostsqlexpress;Initial Catalog=pubs;Integrated Security=True"
but how can I create it on my form??  I would appreciate any help on this matter.
 
(p.s. I am using VWD 2005 and SQLExpress)
 

View 5 Replies View Related

SqlConnection Security

Jul 30, 2007

I have created an aspx page that uses the SqlConnection class to pull data from Microsoft CRM’s database, and we have placed this aspx inside CRM’s directory on the server so that it uses the same integrated security that CRM uses. This works fine on our test environment but on our live environment the Sql connection fails with the exception: "Not associated with a trusted SQL Server connection"
This is probably because our test CRM server has the database on the same machine as the web server, but the live environment has the database and the web server on separate machines.
So my question is how can I create an aspx page that takes the integrated security credentials that the user used to log into the website and uses them to access data from a database on a seperate machine?

View 2 Replies View Related

Re-use Of SqlConnection And SqlCommand ?

Oct 26, 2007

Hi,When using the following controls....System.Data.SqlClient.SqlConnection System.Data.SqlClient.SqlCommandIf I want to change my SQL command and execute the query once again what cleanup do I need to do first?Do I need close and dispose the SqlConnection?Do I need to dispose the SqlCommand?Can I use the SqlConnection for more than one SqlCommand?Thanks,Scott   

View 5 Replies View Related

Problem With SQLConnection

Dec 18, 2007

I am working on a set of webforms that insert user data into a set of db tables. 
I set up a test of an approach using northwind and I'm having trouble getting the insert to work.   When I open the form, input the name and phone, and submit there is no error, but no record inserted into the Shippers table. 
You can see one of my approaches in the ASPX code.  I don't like having to do the select in order to do the insert -- so that's commented off. 
I'm stuck.  Thoughts about what I'm missing appreciated...
 
Ray
 ASPX code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default66a.aspx.cs" Inherits="pages_audit_Default66a" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server"><title>Untitled Page</title>
</head><body>
<form id="form1" runat="server">
CompanyName:
<asp:textbox id="txtCompanyName" runat="server" /><br />
Phone:<asp:textbox id="txtPhone" runat="server" /><br />
<br />
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />
<br />
<br />
<br />
<br />
<asp:Label ID="awesomelbl" runat="server" Text="Label"></asp:Label><br />
<br />
<!--
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
insertcommand="INSERT INTO Shippers(CompanyName, Phone) VALUES (@CompanyName, @Phone)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Shippers]">
<insertparameters>
<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />
<asp:controlparameter controlid="txtPhone" name="Phone" />
</insertparameters>
</asp:sqldatasource>
--></form>
</body>
</html>
c Sharp code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;
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;
public partial class pages_audit_Default66a : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
}protected void btnSubmit_Click(object sender, EventArgs e)
{SqlConnection con = new SqlConnection("Data Source=Chilibowl;Trusted_Connection=yes;DataBase=Northwind");
SqlCommand cmd = new SqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@CompanyName, @Phone)");SqlParameter cnameparam = new SqlParameter("@CompanyName", txtCompanyName.Text); SqlParameter phnparam = new SqlParameter("@Phone", txtPhone.Text);
cmd.Parameters.Add(cnameparam);
cmd.Parameters.Add(phnparam);
try
{
con.Open();if (cmd.ExecuteNonQuery() > 0)awesomelbl.Text = "successful insert";
}
catch
{
//handel
}
finally
{
con.Close();
}
}
}
 

View 2 Replies View Related

Reusing An SQLconnection

Nov 12, 2003

Hi all,
I am accessing one database a bunch of different times all throughout my code...in various functions and different web pages. Is there a a way to create an sqlconnection that I can access all the time, instead of constanting hardcoding which database to go to? I've tried putting the info in another file and just including it where I want the database to open, but I can't use <!-- #INCLUDE --> inside of the server scripts.
Can anyone help

View 1 Replies View Related

OleDbConnection Vs SqlConnection

Jan 22, 2004

Hi,

How much of a performance difference is there between connecting to SQL Server 2000 using OleDbConnection or using SqlConnection?

The reason I'm asking is I am taking on the task of updating an older program that uses a Access Database to use SQL Server, but it has a Database Utility class that uses OleDbConnection. I'm just debating whether it would be worthwhile to upgrade the class to use the SQL objects rather than Oledb. Program does a lot of update and insert of invidual records, and a few select statements that usually return from 1 to 2000 records up to a maximum of 50,000 records

Thanks

View 2 Replies View Related

SqlConnection Failed Sometimes

Mar 2, 2004

I've an web app with impersonate windows authentication. IIS uses Windows authentication for this app & anonymous authentication is turned off.
This app have connectionString in Web.config where Windows autentication (SSPI) to SQL Server 2000 took place.
Now I've a piece of code:

public class SiteParameters
{
public static SqlConnection Connection
{
get
{
SqlConnection conn;
try
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
if(conn.State != ConnectionState.Open)
conn.Open();
}
catch(Exception)
{
conn = null;
}
return conn;
}
}
}

No comments is needed, think...
Now, I'm going to use it in following way:

SqlConnection conn = SiteParameters.Connection;
SqlDataAdapter dta = new SqlDataAdapter();
DataSet ds = new DataSet();

SqlCommand sqlSelect = new SqlCommand("spPlanTransportSelect", conn);
sqlSelect.CommandType =CommandType.StoredProcedure;

dta.SelectCommand = sqlSelect;
dta.Fill(ds, "PlanTransport");

if(conn.State != ConnectionState.Closed)
conn.Close();
return ds;

It looks good & works good... on local machine only :( When I run app locally (doesn't matter if I call it by http://localhost/app, http://127.0.0.1/app or http://10.50.2.51/app I take proper data from database.
But when my buddy from another comp (e.g. 10.50.2.52) uses URL http://10.50.5.51/app he receives an error in line dta.Fill(ds, "PlanTransport");, but in fact conn variable is null & he receives "yellow" screen where is written that NT ANONYMOUS user is trying to log on to database...
It looks strange for me. Any tips?

View 2 Replies View Related

Why My SqlConnection Failed

Jul 10, 2004

I tried connected my web form with SQL server by drag a table from Server Explore onto the WebForm1.aspx. page. It created a sqlConnection1 and a sqlDataadapter object, but theses two objects seem not work. There is nothing displayed on property window and when I right-click sqlDataAdapter there is no "Preview Data", "Configure Data Adapter" and "Gnerate Dataset" items displayed as well.
I used this SQL server on Windows Form, it worked very well. Could anyone please help me figure it out. Thanks!

View 1 Replies View Related

How To Known That Sqlconnection Is Working

Sep 23, 2004

Hello all,
Actually i want to known, is their any method or property in SqlConnection class which will return some value, so that through which we become confirm that connection has established.

Thanks in advance!

View 2 Replies View Related

SqlConnection Problem...Please Help!!

Oct 28, 2004

Hi !!

I have a code that runs from a different machine and a different site and i am facing a problem that i can not log in to the database.I installed SQL Server on my machine and I created a user "fadila" and SQL Server Authentication and the password is "fadil1977" and the database is "otters" and it is installed as tables and stored procedures but there is not data on these tables.

I used the method provided in the code so, i only change the "connStr" in one place rather than in 20 places and my code is as below. Can you please Help me to connect to the database. I Really..Really appreciate it if you help me to solve it as it causeing me a big head-ache and still get the error message "SQL Server does not exist or access denied" .. please help!!!!




Friend Shared ReadOnly Property connStr() As String

Get

Return String.Format( _

"Data Source={0};Initial Catalog=Otters;User ID=fadila;Password=fadil1977", _

DatabaseMachine)

End Get

End Property

View 4 Replies View Related

SQLConnection Control

May 18, 2005

If i use the TimeTracker app from the starter kit suite and I enter my SQL connection in the web.config file it works fine,
 
If i build a simple app with just a sqladapter, sqlconnection and dataset control then enter in the page_load procedure
 
sqlDataAdater1.fill(dataset11)
datagrid1.databind()
It keeps giving my errors see below:  I created a connection with the sqlconnection control and used the same userid and password I used in the time tracker stater kit's web config file which works - I have no idea what is going on
 
*** is it better to create the sqlconnection control first then create the sqladapter or vise versa.
Server Error in '/WebApplication2' Application.


Login failed for user 'IssueTrackerUser'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IssueTrackerUser'.Source Error:



Line 55: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Line 56: 'Put user code to initialize the page here
Line 57: SqlDataAdapter1.Fill(DataSet11)
Line 58: DataGrid1.DataBind()
Line 59: Source File: c:inetpubwwwrootWebApplication2WebForm1.aspx.vb    Line: 57 Stack Trace:



[SqlException: Login failed for user 'IssueTrackerUser'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in c:inetpubwwwrootWebApplication2WebForm1.aspx.vb:57
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()



Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
 

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved