SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
return conn;
}
catch (Exception ex)
{
throw;
}
}
Now I have the execute selectquerry function.....
public static SqlDataReader ExecuteSelectQuerry(string querry)
{
try
{
SqlConnection conn = OpenConnection();
SqlCommand scomm = new SqlCommand(querry, conn);
SqlDataReader sdr = scomm.ExecuteReader();
return sdr;
}
catch (Exception e)
{
return null;
}
}
}
now my question is....the instance of conn is limited only to that function only, and not returned outside. Whereas only the SqlDataReader is returned outside. Does that have any abnormal affect on the application. Since my ASP Application is getting locked (not doing anything, nt even post back!) sometimes after a few DB operation.
Arent these connections and instances Managed (auto garabage collection)?? Can memory leaks under such a situation occur.
I have 2 Excel sheets ( Sheet1 and Summary) in an excel output file. Sheet1 is created and loaded with data fine. Summary sheet is getting the following error: Error: 0xC0202009 at Write Counts and Percentages to Summary Sheet, Excel Destination [337]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E37.
Error: 0xC02020E8 at Write Counts and Percentages to Summary Sheet, Excel Destination [337]: Opening a rowset for "Summary" failed. Check that the object exists in the database.
I do have an execute SQL task to create the summary sheet before the data flow task. The execute SQL task has CREATE TABLE `Summary` ( `Counts_and_Percentages` LongText )
Please advise on what I can do to troubleshoot/correct the error. Thanks
More details on the error DTS.Pipeline] Error: "component "Excel Destination" (337)" failed validation and returned validation status "VS_ISBROKEN". My Excel file name is an expression
I have created my query to do what it needs to do but i'm getting error when i click the button, it says there is an error opening my connectiong.... I.E. Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. 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 '(null)'. Reason: Not associated with a trusted SQL Server connection.Source Error:
Line 28: Line 29: //open the connection Line 30: myConnection.Open(); Line 31: Line 32: //create a commandSource File: c:Documents and SettingsplanPlanDatabaseBZAvuAdd.aspx.cs Line: 30 Stack Trace:
Hi most of my code follows the following format in a lot of my pages, my question is; Am i approaching it the right way in terms of performance, sql injection attacks and anything someone more knowledgeable than myself can think off, please feel free to criticise the code. Thank youprotected void Page_Load(object sender, EventArgs e) {string strID = Request.QueryString["id"]; SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["streamConnectionString"].ConnectionString);SqlCommand command = new SqlCommand("stream_EventsByID", conn); command.CommandType = CommandType.StoredProcedure;command.Parameters.Add("@eventID", SqlDbType.Int).Value = Request.QueryString["id"]; conn.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); eventList.DataSource = reader; eventList.DataBind(); conn.Close(); } }
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to connect to the DB from within my code. I've created a .vb class that houses a private Connection() that other functions within the class can call to connect to the database. In the calling function, I've declared my connection object and called the "Open" method on the object. However, when I attempt to execute the stored procedure command by calling the "ExecuteScalar" method, I get the following error: "ExecuteScalar requires an open and available Connection. The connection's current state is closed." Here's the code from my class: Imports System.Data Imports System.Data.SqlClient Namespace Encompass Public Class EncompassSecurity Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String Dim strHRID As String 'Create command object Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection()) cmd.CommandType = CommandType.StoredProcedure 'Open DB connection Dim DBConnection As SqlConnection = Connection() DBConnection.Open() 'Input parameters Dim inNTUserParam As New SqlParameter("@NT_UserID", SqlDbType.VarChar) inNTUserParam.Direction = ParameterDirection.Input inNTUserParam.Value = strNTUserID cmd.Parameters.Add(inNTUserParam) 'Output parameters Dim outHRIDParam As New SqlParameter("@HRID", SqlDbType.Int) outHRIDParam.Direction = ParameterDirection.Output cmd.Parameters.Add(outHRIDParam) 'Run stored procedure strHRID = cmd.ExecuteScalar() Return (strHRID) 'Close DB connection DBConnection.Close() End Function Private Shared Function Connection() As SqlConnection Dim strConnectionString As String strConnectionString = ConfigurationManager.ConnectionStrings("Conn").ConnectionString Return New SqlConnection(strConnectionString) End Function End Class End Namespace Here's the code from my web.config file: <?xml version="1.0"?> <!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in WindowsMicrosoft.NetFrameworkv2.xConfig --> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <connectionStrings> <add name="Conn" connectionString="Data Source=ServerName;Initial Catalog=NPASDV;uid=UserName;password=*******;" providerName="System.Data.SqlClient" /> </connectionStrings>
<system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. Visual Basic options: Set strict="true" to disallow all data type conversions where data loss can occur. Set explicit="true" to force declaration of all variables. --> <roleManager defaultProvider="AspNetWindowsTokenRoleProvider" /> <compilation debug="true" strict="false" explicit="true" /> <pages> <namespaces> <clear /> <add namespace="System" /> <add namespace="System.Collections" /> <add namespace="System.Collections.Specialized" /> <add namespace="System.Configuration" /> <add namespace="System.Text" /> <add namespace="System.Text.RegularExpressions" /> <add namespace="System.Web" /> <add namespace="System.Web.Caching" /> <add namespace="System.Web.SessionState" /> <add namespace="System.Web.Security" /> <add namespace="System.Web.Profile" /> <add namespace="System.Web.UI" /> <add namespace="System.Web.UI.WebControls" /> <add namespace="System.Web.UI.WebControls.WebParts" /> <add namespace="System.Web.UI.HtmlControls" /> </namespaces> </pages> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" />
<!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> </configuration> What am I doing wrong? Any help would be most appreciated!! Manuel
I know that opening a connection to a DB is expensive. Usually I write a method that opens a connection to the DB then I execute a query and then close the connection. Pretty standard.
OK, so how do I handle opening connections to the database when I need to run multiple queries. For example, i have a webpage that need to query the database to see if the user has moderator privledges, then depending on that query I have to query the DB again for moderator specific information or non-modertaor information.
So in this case how do i handle opening connections to the DB. Is it ok to generally have to open a connection to a DB multiple times on a page load?
The obvious solution is to keep the connection open. That is, open a connection, query the Db, keep the connection open, do the conditional statment ( if is_Moderator) then query the DB again for the info that I need, and then close the connection. But, from all the books that Ive been reading this is not a good practice because business logic should not been in the dataAccess layer.
When the databse file's "copy to output" property is set to "copy always" my data is not saved and when I change it to "do not copy" it gives me the error "cannot attach the database file", and does not open my connection. I dont know what to do.....
i have a loop that can run say 30k times. in there i am using the try / catch / finally blocks to handle ADO.NET Transactions (thanks CADDRE!)Should i open and close the SQL Connection for each record? or open it and close it outside of the loop only once ?thanks in advance, mcm
at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at WebService1.Service1.HelloWorld() in g:inetpubwwwrootwebservice1service1.asmx.cs:line 120
My guess is that something in the web.config isn't right or maybe the host (webfusion) is strange. Thanks if anyone can help.
I have a application running on Biztalk server , VS 2008 and SQL server 2008.
I have opened a SQL connection string and referring some DB which works absoluetly fine.
But in my code in C#, i try to open another connection with some different database, as i apply the connection.open(), it gives me a very strange error of Sql server 2005. And i dont have Sql 2005 on my box.
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) (Microsoft SQL Server, Error: 53)
I am getting the error message below when trying to connect to SQL Server 2000. Here are the details:
Problem is occuring with a new website trying to connect to SQL Server. The error occurs right at the open statement. Using SQL Server 2000 Web server is on a different machine than SQL Server I have many websites connecting to this SQL Server. Websites are all on the same webserver. I can connect to this SQL Server using the Query Analyzer using the same ID and PW as in my connection string My web application runs OK using this SQL Server when I run it from my laptop - just changed the connection string Initial Catalog parameter. Any help would be appreciated. Jay --- Error Message 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)
(Hope this isn't a "stupid" question, but I haven't been able to find a straight-forward answer anywhere)" I currently have code that iterates through a dataview's records, making a change to a field in some of the records. The way I have this coded, a conection has to opened & closed for each individual record that's updated: dsrcUserIae.UpdateCommand = "UPDATE UserIAE SET blnCorrect = @blnCorrect WHERE (ID = @ID)" dsrcUserIae.UpdateParameters.Add("blnCorrect", SqlDbType.Bit) dsrcUserIae.UpdateParameters.Add("ID", SqlDbType.Int) Dim myDataView As DataView = CType(dsrcUserIae.Select(DataSourceSelectArguments.Empty), DataView) For Each myRow As DataRowView In myDataView If myRow("FkUsersAnswerID") = myRow("AnswerID") Then intCorrect = 1 Else intCorrect = 0 End If dsrcUserIae.UpdateParameters.Item("blnCorrect").DefaultValue = intCorrect dsrcUserIae.UpdateParameters.Item("ID").DefaultValue = myRow("ID") intUpdateResult = dsrcUserIae.Update() Next It seems like I should be able to do something like this (call update once), but I'm not sure how... dsrcUserIae.UpdateCommand = "UPDATE UserIAE SET blnCorrect = @blnCorrect WHERE (ID = @ID)" dsrcUserIae.UpdateParameters.Add("blnCorrect", SqlDbType.Bit) dsrcUserIae.UpdateParameters.Add("ID", SqlDbType.Int) Dim myDataView As DataView = CType(dsrcUserIae.Select(DataSourceSelectArguments.Empty), DataView) For Each myRow As DataRowView In myDataView If myRow("FkUsersAnswerID") = myRow("AnswerID") Then myRow("blnCorrect") = 1 Else myRow("blnCorrect") = False End If Next intUpdateResult = dsrcUserIae.Update() 'Want all changed myRow("blnCorrect") to be updated to datasource Can anybody explain how to do the bulk update? I've seen some info about AcceptChanges and Merge, but I'm not sure if they apply here, or if they more for Transactions.
I'm writing an application with Visual Studio 2005 (Visual Basic .NET 2.0) which uses a SQL Compact Edition 3.5 database. On my HTC Touch with Windows Mobile 6.1 installed the application crashes, without any error message, if I try to open a connection. But...On the Windows Mobile 6 Pro emulator the connection opens normaly. The whole application runs perfect. On both "devices" are the same dll's, of version 3.5.0.0.
I'm using the following code to open the connection:
Dim localConnection As New SqlCeConnection(mySQLce_strConnection) localConnection.Open()
I tried so many things but without any success. But...I'm able to open the database (MControl_SQLce.sdf) with the Query Analyzer 3.5 on the Mobile. No problem.
This is my configuration: Dev PC: Windows XP SP2 Visual Studio 2005 Pro .NET Framework 2.0 SP1 .NET Compact Framework 2.0 SQL Server Compact Edition 3.5 (this version I reference to in my VS project)
Mobile Device (HTC Touch): Windows Mobile 6.1 SQL Server Compact Edition 3.5
Hello everyone. I'm very new to asp.net. I've been coding in vb.net for a while now (getting my associates degree in desktop application programming) and my boss wants all of my new applications to be web based now. Well, i decided to take some initiative on this and begin a new project for my department. This is a very small project. So far, everything is coming along alright (i found an eBook that's helped me quite a bit). Everything was cool until yesterday when i tried to connect to our sql server database. I get an error message stating:
Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
Because i'm testing this on my system as well as the remote system which hosts the application, i can see the error message on the remote system. Here is the error it's giving me:
Server Error in '/' Application. --------------------------------------------------------------------------------
Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. 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 '(null)'. Reason: Not associated with a trusted SQL Server connection.
Source Error:
Line 57: sConnString = "Server=F11602A2120564OPS;Initial Catalog=OpsMonitor;User ID='public';Password=;Integrated Security=SSPI;"'Connection String Line 58: sConn = New SqlConnection(sConnString)'Initialize New Connection Line 59: sConn.Open'Open the connection Line 60: End Sub Line 61: </script>
[SqlException: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.] System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474 System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372 System.Data.SqlClient.SqlConnection.Open() +383 ASP.atm_reporting_aspx.OpenConn() in c:inetpubwwwrootatm_reporting.aspx:59 ASP.atm_reporting_aspx.Page_Load(Object Src, EventArgs E) in c:inetpubwwwrootatm_reporting.aspx:23 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Page.ProcessRequestMain() +731
You can see my SQL Connection string in there as well. Can someone please help me with this? I can post the code to the entire page as well if that would help. I'm developing this with Dreamweaver MX 2004 (i like dreamweaver MUCH better than visual studio, especially for web design/development). Thanks,
I am getting an error in Replication between SQL Server 2005 and SQL Express when "Connecting to Subscriber". Detailed error message is given below. Do we need to increase the logintimeout for "Connecting to Subscriber". How can we increase it?
Message 2007-10-15 06:37:58.398 Startup Delay: 8503 (msecs) 2007-10-15 06:38:06.898 Connecting to Distributor 'ACR-MANGO' 2007-10-15 06:38:06.976 Initializing 2007-10-15 06:38:06.976 Parameter values obtained from agent profile: -bcpbatchsize 2147473647 -commitbatchsize 100 -commitbatchthreshold 1000 -historyverboselevel 1 -keepalivemessageinterval 300 -logintimeout 15 -maxbcpthreads 1 -maxdeliveredtransactions 0 -pollinginterval 5000 -querytimeout 1800 -skiperrors -transactionsperhistory 100 2007-10-15 06:38:06.991 Connecting to Subscriber 'ACR-ANJILISQLEXPRESS' 2007-10-15 06:38:46.133 Agent message code 20084. The process could not connect to Subscriber 'ACR-ANJILISQLEXPRESS'. 2007-10-15 06:38:46.148 Category:NULL Source: Microsoft SQL Native Client Number: 08001 Message: Unable to complete login process due to delay in opening server connection 2007-10-15 06:38:46.148 The agent failed with a 'Retry' status. Try to run the agent at a later time.
Hi, I am using VS2003. I have installed .net2.0 so that I can run SQL Express. I am using XP Pro SP2. My server is called ikitsch. The path to my database is ikitschsqlexpressDatabasesTest1 I am using windows authentication. For some reason I can't seem to connect to the database. What would be a correct connection string to connect to this database on my local machine? Thanks
Assume I have an asp.net/sql server 2000 web app in a shared hosting environment. I then encrypt the connection string using ProtectSection("DataProtectionConfigurationProvider") in the page load of my default.aspx page.
Am I understanding the following concepts then correctly?
1. I upload the site to the shared hosting server. 2. The first time I run the app eg. www.whatever.com/default.aspx, the ProtectSection method above is executed. 3. Now the conn string area of my web.config is encrypted, and asp.net will decrypt as needed.
4. If someone were to hack the server and view the web.config -- whether via getting into the server or via ftp, they would see an encrypted connection string. Thanks very much!
I’m trying to follow the article http://aspnet.4guysfromrolla.com/articles/031506-1.aspx. It gives a sample to download at the bottom which I did. I’m trying to take a look at the Stored Proc that were created in the PagingData.mdf. The only thing included in the App_Data folder is PagingData.mdf file. How can I open the DB or attach it to my SQL2005 server? There is no .ldf file included in the sample so the attaching is failing.
I used to use rdo in VB6 and now I'm trying to figure out how to use the SqlDataReader class in VB.NET. I want to use an ODBC data source to specify the connection info. I used to give the rdoConnection object a connect string that looked something like this:"DSN=[data source name];UID=[sql server user];PWD=[pwd]"I don't understand the connect string given in all the examples I've found (nor does it seem to work on my system...) mySqlConnection = New SqlConnection("server=(local)VSdotNET;Trusted_Connection=yes;database=northwind")Does anyone have any ideas? I'm open to explanations as well as solutions :)Thanks,jdm
I got a .dts package via email. But I am not able to open it in my sql server. Could some one pls help me know, how to open .dts packeges in the designer.
All I want to do is open an .mdf file. So I have downloaded and installed SQL Server 2005 Express Edition. I have searched HELP but I see nothing simple. How do I add a file to this server so that I can read the file in Access? Thank you very much for any help you can give. David Thomas
Hi, I have a client who has a current website based on an MS SQL database. I am building a new website that will be in MySQL.
I have never used MSSQL before and the only information that i have been sent by the old web designer is a .bak file (which is the latest back-up of the MS SQL info) and the user name and password for the current on-line databases.
I dont know how to open this .bak file, ideally i would like to get it into MS excel or MS access. I have downloaded SQL Server Management Studio Express and SQL Server Configuration Manager but i dont know what to do next (and am really confused!)
Can anyone advise me of the steps that i need to take to get the data out of the .bak file?
Hello Guys, One of the fields in my report is a web address (i.e. http://www.yahoo.com). Navigation property for this field is "Jump to URL". Users will access the report with a browser, using a "sharepoint-like" application. Default behavior of "Jump to URL" seems to be to open the link in the same window (or tab in IE7). Is there a way to force the link to be open in the new window?? Please let me know if you have any suggestions. Thanks!!
Im using Sql server 2000. I wanted to know if its possible to open a cursor using an sp instead of an sqlstatement?
Also I know that cursors cant be opened for more than one result sets. This question is based on the assumption that the SP will return only one result set.
If possible please let me know the syntax/reference link.
Hello, I put my stored procedure in my class and try to execute it but get this error 1st here is my class 1 public signup_data_entry() 2 { 3 SqlConnection con = new SqlConnection("cellulant_ConnectionString"); 4 5 6 SqlCommand command = new SqlCommand("Cellulant_Users_registration", con); 7 command.CommandType = CommandType.StoredProcedure; 8 9 con.open(); 10 11 command.Parameters.Add(new SqlParameter("@RegionID", SqlDbType.Int, 0, "RegionID")); 12 command.Parameters.Add(new SqlParameter("@RegionDescription", SqlDbType.NChar, 50, "RegionDescription")); 13 14 command.Parameters[0].Value = 4; 15 command.Parameters[1].Value = "SouthEast"; 16 17 int i = command.ExecuteNonQuery(); 18 19 20 }
and here is the error message on the testing server. Error line is line 27 below
Source Error:
Line 25: command.CommandType = CommandType.StoredProcedure; Line 26: Error >>> Line 27: con.open(); Line 28: Line 29: command.Parameters.Add(new SqlParameter("@RegionID", SqlDbType.Int, 0, "RegionID"));
I Have A Problem With Opening A Database With "SQLOLEDB" Provider In Web Application Projects! The Same Database Opens In Windows Application Projects But When I Try TO Open It (Manually Or During A DataAdapter.Fill Method) In Web APPS I Get An Error Message : "Login failed for user 'NT AUTHORITYNETWORK SERVICE'." I Use Windows NT Authentication In Connections, I Have SQL Server 2000 Enterprise Edition (With Default Installation) , Windows .Net Server 2003 Enterprise Edition (IIS 6) , And VS.NET 2003 Enterprise Edition (.Net Framework 1.1) Can Anyone Tell Me What's Wrong?
Hi,I am getting this error when i am connecting sql database.Error = "SQL Server does not exist or access denied."Can you please suggest me where i am going wrong.RegardsNaveen
If Someone could please show me some example VB code where i can open the my Sqlconnection in the Page_Load subroutien... and then close that SqlConnection in the Page_Unload routine. I want to be able to execute Sql command without having to re-open and re-close the connection.
When using Enterprise Manager, Right Clicking on any table in the db, selecting OPEN TABLE, and choosing either Return all rows or Return Top... I recieve this error "The query cannot be executed because some files are missing or not registered. Run setup again to make sure the required files are registered."
I am running: SQL Server 7.0 Client with Windows 2000.
I have run setup again and the same thing still happenes. I even uninstalled and reinstalled SQL Server, still the same thing occures.
I first installed SQL Server7.0 on my machine about a month and a half ago and all was fine until two weeks ago, then this started happening. SQL Server was the last thing I have installed on this machine so it cannot be a new install conflict. I can't think of any reason for this to be happening out of the blue like it did.
My client has given me a DB file (.MDF) and I need to open it in order to export it to the remote DB. In Enterprise Manager I go to 'New Database' - create a new DB and click on the 'Data' tab to browse to my clients file. Enterprise Manager recognises the file and everything seems hunky dory. but the resulting DB seems to have no tables. The DB file is 1600K and has some stored procedures but if I try to export the tables there is nothing. His ASP files refer to tables in the SQL as you would expect. Am I missing something? it's the weekend so he is not available and I don't want to look tooo stupid!
I am having one problem about the processing cube in SQL 2005 AS. when cube runs i get this error in log file:
File system error: Error opening file; Program Files (x86)Microsoft SQL Server90SharedASConfigmsmdredir.ini is not a disk file or file is not accessible.