Cannot Open Connection To Access Database.

Jan 1, 2007

I am very new to VB.Net but my goal is to build a web app that ineracts with an Access database. This is a very small scale app so I am not interested in using SQL server. I created my Access database and the udl file for connection information.



I created a class that opens a connection to the database when the webpage loads.



I get the following error though,

System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147467259
Message="The Microsoft Jet database engine cannot open the file 'C:InetpubwwwrootTest1RaceData.mdb'. It is already opened exclusively by another user, or you need permission to view its data."
Source="Microsoft JET Database Engine"
StackTrace:
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at clsDBConn.Open_Connection() in c:inetpubwwwrootTest1App_CodeclsDBConn.vb:line 12
at Default2.Page_Load(Object sender, EventArgs e) in c:inetpubwwwrootTest1Default2.aspx.vb:line 8
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)




The database is not open so I know it is a matter of security. I have configured IIS to use an admin account and the Access db does not have security turned on. In the UDL file I have selected read/write access and the test connection works.



Can anyone help me narrow down the root of this error,



Thanx in advance,

Chris

Topfuel5

View 1 Replies


ADVERTISEMENT

.Net 2003 Access Crystal Report XI: Error:Failed To Open The Connection: [Database Vendor Code: 17 ]

Sep 19, 2006

I am receving this error: Failed to open the connection: [Database Vendor Code: 17 ], from .Net 2003/C# to Crystal Report XI with SQL Server 2000 has backend database.

Is there a security permission that has been overlooked?

Here is the code I use to access CR XI

ConnectionInfo connectionInfo = new ConnectionInfo();
TableLogOnInfo tableLogOnInfo;
Database DB;
'CrystalDecisions.CrystalReports.Engine.Table' table;
Tables tables;

//Log in
connectionInfo.ServerName = "ServerName";
connectionInfo.DatabaseName = "Database Namet";
connectionInfo.UserID = "userid";
connectionInfo.Password = "password";

//Get Table inf from report
DB = reportDocument..Database;
tables = DB.Tables;


//Looping through all the tables in CR and apply connection info
for(int i = 0; i < tables.Count; i++)
{
table = tables[ i ];
tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);

}

CrystalReportViewer.ReportSource = ReportDocument.ReportSource;
CrystalReportViewer.Visible = true;

Any advise would be helpful.
Thank you

View 6 Replies View Related

Access Denied | Connection Open | Create File()

Aug 18, 2001

When i try to connect my sql client to my sql server on the internet i get a error message :" Access denied | connection open | create file()"

plz help

shailesh

View 2 Replies View Related

Data Access :: Error 40 - Could Not Open A Connection To Server

Feb 23, 2014

i am getting following error

Error 40 - Could not open a connection to SQL Server

View 4 Replies View Related

The Microsoft Jet Database Engine Cannot Open MS-Access Database

Aug 18, 2007


I have MS-Access as data source for one of the reports. I can preview the report fine from BI studio however, it does not work when I deploy it on report server.

The error is :

An error has occurred during report processing.
Cannot create a connection to data source '<data source name>'.

The Microsoft Jet database engine cannot open the file '<UNC location of the MS-Access database>'. It is already opened exclusively by another user, or you need permission to view its data.




MS-Access database is located on a different server.

Any help to solve this? I understand it has something to do with permission both on server where reporting service is running as well as the server where MS-access database is located. Pls help.

View 2 Replies View Related

Failed To Open A Connection To The Database

Nov 21, 2007

Hello,



          I receive
this error when choosing the data connection in TableAdapter Wizard for me to
reference the ASPNETDB.mdf database.



Failed to open a connection to the database









"The header for file
'C:InetpubwwwrootWebsites4App_DataASPNETDB.MDF is not valid databasefile header. The FILE SIZE property is incorrect.An attempt to attach an auto-named database exists, or
specified file cannotbe opened, or it is located on UNC share."

Check the connection and try again.







 I already have the connection at config but the error
persists. 













... 
<connectionStrings>    <add
name="ConnectionString1" connectionString="Data
Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|mydatabase.mdf;Integrated
Security=True"providerName="System.Data.SqlClient" />    <add
name="ASPNETDBConnectionString1" connectionString="DataSource=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated
Security=True" providerName="System.Data.SqlClient" /> 
</connectionStrings>  <system.web>...  cheers,imperialx 

View 2 Replies View Related

Database Connection - Don't Have Permission To Open File

Nov 4, 2007

Database Connection - Don't have permission to open file

I'm trying to establish a connection to a database file (c: empMine.mdf) through visual studio c# express 2005 edition.
I'm using the database explorer/add connection wizard.
On the add connection dialog window when i browse and select the db file to connect to i'm getting the message
"You don't have permission to open this file. Contact the file owner or an administrator to obtain permission"

I have SQL Server Express 2005 and SQL Server Management Studio Express installed.
Within the management studio at the server security level i'm mapped to the db file
(Mine.mdf) and have db_owner and public ticked and have also set the default database
as Mine
At the database security level under usersproperties i have also ticked db_owner.
Also when i select properties for the db file itself it's telling me that i'm the owner.

I'm also using vista home premium edition and using windows authentication instead of
sql server authentication.

I'm fairly new to all this so there may be something glaringly obvious i've missed!

Thanks.

View 15 Replies View Related

Canīt Open Sql Database Tables From Access Adp Project

Apr 1, 2004

hi there,

we canīt open most of the sql server tables from our Access
project any more, which has to be related to collation or
extended property problems.

trying to open any table will result in the information
"The stored procedure has been executed but did not return
any records" after the first try
and later on nothing will happen any more; tables wonīt
open.

basically this started to happen after recreating the sql
database due to resolution 1 in Microsoft Knowledge Base
Article - 318989:
collation of the server is Latin1_General_CI_AS
collation of the old database was
SQL_Latin1_General_CP1_CI_AS, which led to the error
described in the article.
collation of the new database is set to <Database
Standard>, now i have the problems described above.

anybody some good help on that?

ps: we canīt really rebuild the user database all the
time, because we got flight data in about 4 billion
records in there, so we will need anything quick and
easy...
thanks

ron

View 2 Replies View Related

Datareader Can Not Open Connection To My Database For Login Myusername

Feb 1, 2007

  This is my page_loads event code and iam getting the Exception pasted below the code.
-----------------------------------------------------------------------------------------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
Dim myconnection As New SqlConnection("Data Source=localhostSQLEXPRESS;initial catalog = safetydata.mdf;Integrated Security=True;User Instance=True")
Dim strSQL As String = "SELECT Incident_Id,Emp_No From Report_Incident"
Dim mycommand As New SqlCommand(strSQL, myconnection)
myconnection.Open()
Dim reader As SqlDataReader = mycommand.ExecuteReader()
 
Dim chart As New PieChart
chart.DataSource = reader
chart.DataXValueField = "Incident_id"
chart.DataYValueField = "Emp_No"
chart.DataBind()
 
chart.DataLabels.Visible = True
 
ChartControl1.Charts.Add(chart)
ChartControl1.RedrawChart()
myconnection.Open()
 
End If
End Sub
 -------------------------------------------------------------------------------------------------------------------------------
EXCEPTION IS BELOW
Cannot open database "mydatabase.mdf" requested by the login. The login failed.Login failed for user 'myusername'.
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: Cannot open database "safetydata.mdf" requested by the login. The login failed.Login failed for user 'myusername'.Source Error:



Line 18: Dim strSQL As String = "SELECT Incident_Id,Emp_No From Report_Incident"
Line 19: Dim mycommand As New SqlCommand(strSQL, myconnection)
Line 20: myconnection.Open()
Line 21: Dim reader As SqlDataReader = mycommand.ExecuteReader()
Line 22: Source File: C:Incident Reporting System--Trial VersionWebChart.aspx    Line: 20 Stack Trace:



[SqlException (0x80131904): Cannot open database "safetydata.mdf" requested by the login. The login failed.
Login failed for user 'myusername'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +171
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2305
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +34
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +606
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +193
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +501
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +429
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +70
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +512
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
System.Data.SqlClient.SqlConnection.Open() +160
ASP.webchart_aspx.Page_Load(Object sender, EventArgs e) in C:Incident Reporting System--Trial VersionWebChart.aspx:20
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3745



Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.

View 1 Replies View Related

How Do I Know Whether The Connection Is Open With The Sqlserver Database While Work In The Application?

Oct 22, 2007

How do i know whether the connection is open with the sqlserver database while work in the application?

View 2 Replies View Related

Unable To Open A Connection To Report Server Database

Mar 14, 2008



hi,

I created ReportServer by reporting services configuration and i gave the local and remote permissions using surface
area cofiguration using tcp/ip only. But when i browse the reportserver i got the below mentioned error.


The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing. (rsReportServerDatabaseUnavailable)

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 5 Replies View Related

SQL Security :: Can't Open Database File Access Denied

Aug 17, 2015

Event 17204, FCB::Open failed: Could not open file F:MSSQLDatafilename.mdf for file number 1.  OS error: 5(Access is denied.).When I look at the file permissions of filename.mdf, there is no MSSQLSERVER group permissions listed nor can I add it. I have tried to add MSSQLSERVER and NT SERVICEMS SQL $MSSQLSERVER but neither exist. There is also a ReportServer.mdf in the same folder with MSSQLSERVER permissions!Did I somehow delete this group? What can I do to restore this permission?

View 6 Replies View Related

Data Access :: Server Rejected The Connection - Access To Selected Database Has Been Denied

Jun 10, 2015

I have recently upgraded to SQL2014 on Win2012. The Access front end program works fine.

But, previously created Excel reports with built in MS Queries now fail with the above error for users with MS 2013.  The queries still work for users still using MS 2007. 

I also cannot create any new queries and get the same error message. If I log on as myself on the domain to another PC with 2007 installed it works fine, so I don't think it is anything to do with AD groups or permissions.

View 6 Replies View Related

Data Access :: Cannot Open Database After Changing Its Name And Change Back To Its Original Name

Sep 3, 2015

I cannot open now my database after changing it name from the folder where it is save and also changed back to its original name.Message recovery pending now is appearing as shown below.Any chance that I could recover my database back?

View 17 Replies View Related

Leave The Connection Open Or Always Open And Close Immediately?

Jun 7, 2006

Hi there,
 
I got an approach like that:
1) Read something from DB - check the value, if true stop if false go on2) Read the second Value (another SQL Statement) - check the value etc.
Now I could open the connection at 1) and if I have to go to 2) I leave the connection open and use the same connection at 2). Is it ok to do that?
The other scenario would be opening a connection at 1), immediately close it after I read the value and open a new connection at 2).
Thanks for the input!

View 4 Replies View Related

Error Message: Cannot Open Database.[DBNETLIB][ConnectionOpen(Connect()).] SQL Server Does Not Exist Or Access Denied.

Mar 20, 2008

I installed SQL 2005 including backward compatibility, MSDN libraries and SP2 a new Windows 2003 server (chose mixed mode authentication). Installation was successful and I then installed an off the shelf database with Windows authentication which also installed successfully.
I created a new group in AD, added the database users into the group and gave db-owner rights to the group in SQL as advised by the installation guide. However, when I try to open the database it gives an error message saying "Cannot open database.[DBNETLIB][ConnectionOpen(Connect()).] SQL server does not exist or access denied". I also tested it adding an individual user (myself) as a user to no avail.
When I set up DSN in ODBC on my computer I can successfully test the connection but can't run the application. The connection is via TCP/IP.
Any suggestions?

View 7 Replies View Related

ODBC Connection From Access 2007 Database To SQL Server 2005 Database

Feb 29, 2008

I need detailed instructions on how to connect to a database from a Microsoft Access 2007 database to a Microsft Office Accounting 2007 database. The accounting database is an SQL 2005 datbase. It has an instance name of "MSSMLBIZ".

When I try I get an SQL error 53. Do not have permissions or database does not exist.

Thanks in advance for any help.,

View 1 Replies View Related

ExecuteReader Requires An Open And Available Connection. The Connection's Current State Is Closed.

Apr 26, 2007

I am accessing SQL2005 with C# code using OleDbConnection.



A try and catch block catches the following error once a while between the Open() and Close() of the connection:

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



I do not even have any idea where to start to debug this. The ExecuteNonQuery() runs a delete SQL query. It works 99.9% of the time. I do not see anything wrong when this error happens.



Any hint would be greatly appreciated.



View 9 Replies View Related

Can't Find SQL Native Client In ODBC Connection Manager In SQL Server Open Database Connectivity (ODBC)

Feb 13, 2007

I apologize if this is not the correct forum for this posting. Looking at the descriptions, it appeared to be the best choice.

I am running Windows XP Pro SP2. I have installed the SQL Native Client for
XP. However, when I try to add a new data source through ODBC Connection
Manager, SQL Native Client is not listed as an option. I have followed this procedure on three other systems with no problems. What would be causing the
SQL Native Client to not show up in the list of available ODBC data sources?

View 4 Replies View Related

Access Connection To Hosted Database?

Jun 28, 2012

I have a SQL Server 2005 database hosted by a provider that has about 500 databases on their site. I am running Access2007 on a Windows 7 Home Premium edition.

What I am trying to do is create a new Access2007 application and attach (i.e: Link) to the SQL Server tables. I am using SQL Authentication.

I have done this before where i attached via ODBC to Oracle, but it was on the corporate network - not on a hosted server. When i try to walk thru the Access process, it does not seem to let me give it the database name. I have the connection string i use in C# (for example: Data Source, Initial Catalog, UserID and Password), how to connect with Access2007.

View 4 Replies View Related

Find Database Access By Tcp Connection

Feb 10, 2004

Ok, lets see if I can put what I am looking for into words.
I run a MSSQL server, I show in my logs that a connection is being made to my server from a remote ip. I have contact the owner of the ip in question and they state that they have no buisness with us and they should not be connected to us. According to netstat the connection to us is established on 2 different remote ports to 1433. My question, is there any logging on sql that I can turn on, look at to see what database this connection is accessing? Thanks

View 5 Replies View Related

Vc++ 2005 Connection Access Database

Aug 16, 2007



Dear all
if i want to write one program use vc++2005 to connection access database with MFC system , which idea is best.
does any sample code i can use in this case or any concept i can read it first?

best regard
roger

View 1 Replies View Related

How To Create A Connection To Access Database

Dec 27, 2006

Hi guys,

I want to create a report from Access Database. Can anybody tell me how to connect and create a data source from Access data source. A step by step guide is preferable. I am more concerned on the connection string.

Thanks.

View 5 Replies View Related

Cannot Open User Default Database. Login Failed. (only When IDE Is Open)

Sep 7, 2007

I get the below error only when my IDE open. It connects well when it is found closed.
[SqlException (0x80131904): Cannot open user default database. Login failed.Login failed for user 'JPASPNET'.]
I could solve this by giving the logged in windows user to impersonate under IIS window > WEBSITE > ASP.NET tab > EDIT CONFIG > APPLICATION tab
But I wish someone could give me the proper solution.
I almost tried all from giving ASPNET user as a administrator to configuring the same in Express management tool.
Environment: XP pro, VWD and SQL Express

View 3 Replies View Related

Analysis Service Connection To Access Database

Feb 22, 2004

Hi

I was doing steps on page 15 of attached sheet


I was doing the microsoft example about cube to setup DSN SOURCE CONNECTION to ACCESS database (food mart) when i do a test

but after i do design storage and go to Process the cube
it gives me error

'test connection failed because of an error in initializing provide
(microsoft) ODBC DRIVER manager data source name not found and no default driver specified

one more error found
Microsoft ODBC DRIVER MANAGER driver sql connect attr failed: IMOO6

Thanks

View 2 Replies View Related

Open An ODBC Connection To A DB And Must Use A Connection That Looks Like This: DSN=myDSNname.

Dec 11, 2006

In my ssis package,

I have a DSN connection like this: "DSN=myDSNname". Which decide from i have to pull the data.

By using OLE DB Source Editor, I want to assign that ODBC Connection to it.

By data source Reader i can achive this but where i have to pass the hard-code SQL Query that i don't want.

i'm using the variable for dynamic SQL command.

Thanks.

Manoj

View 5 Replies View Related

Error While Establishing A Connection To The SQL Server 2005 - Could Not Open A Connection To SQL Server

Apr 12, 2007

Hi, I had an old web application created during asp.net 1.1 and it have a connection problem with the sql server 2005 when it is mirgrated to a new webserver with dotnet framework 2.0 platform. I have enabled the remote access(TCP/IP and named pipes) in sql server 2005, did all the neccessary things, check whether the TCP/IP is enabled, named pipe is enabled...  I created another web application using VS 2005. The database connection works perfectly well.This are the connectionString from the old web application.<appSettings>    <add key="ConnectionString" value="Server=127.0.0.1;Database=somedb;User id=user; Password=somepassword; Trusted_Connection=False; POOLING=FALSE"/></appSettings>  Thankyou in advance! 

View 4 Replies View Related

Getting The Report Server Cannot Open A Connection To The Report Server Database Error

Jul 5, 2007

Hi



I went to my comp ->rt cick->manage-IIS->default website->rt click->properties->directory security->annoymouse access€ĶEDIT->under Default domain it was blank, and i added a domain there.



And i was getting error opening up the reports from localhost.



I changed everything to same as it was previosly, and I am getting the error:

The report server cannot open a connection to the report server database. A connection to the database is required for all requests and processing. (rsReportServerDatabaseUnavailable) (rsRPCError) Get Online Help










Cannot open database "ReportServer$SQLExpress" requested by the login. The login failed. Login failed for user 'NGESComputer name$'.

View 1 Replies View Related

Open Connection

Nov 1, 2007

Hello everybody I would like to know more about the number of possible connection to a sql server is it by pool ? or there is max for all the database ? all the server ? how I can get the number of connection open ? Thx in advance 

View 2 Replies View Related

Could Not Open Sql Connection

Sep 22, 2007



Hi,
I hope this is right place to ask for help.If it is not, Please show me where and if it is please Help me
I using Window Vista bussiness, Microsoft visual 2005 professional edition, Microsoft SQL server express edtion
I have created table on Database.
My sql server name is KYAW-HQ
**but in the bar it shown like as KYAW-HQSQLEXPRESS
My data base name is kyaw
I have already Enabled Name Pipes and TCP/IP setting in sql studio management tool express
I using window authentication to log in to sql server management studio express.

My coding for c# is as follow:


private void button4_Click(object sender, EventArgs e)

{

//connect sql connection

SqlConnection con = new SqlConnection("Server=KYAW-HQ;Database=kyaw;UID=;PWD=;");

//open sql conection

con.Open();

SqlDataAdapter ad = new SqlDataAdapter("Select * From kyaw", con);

DataSet ds = new DataSet();

ad.Fill(ds, "kyaw");

dataGridView1.DataSource = ds.Tables[0].DefaultView;

con.Close();





}



After I click the button the error has shown like below

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).

Please tell me what i have to do.
If someone read me, please tell me and advice me how to fix above problem.
Thanks

View 9 Replies View Related

Cannot Open SQL Connection

Jan 22, 2008

Hello!

This code sample stops when I try to open a connection (see below). Ther error message reads "pipe provider , error 40". The help suggests that the credentials are wrong. I donīt think so, could there be another problem? Tough question but, I would appreciate any help.


System.Data.SqlClient.SqlConnection sqlConnection1 =

new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["SwimAdminConnectionString"].ConnectionString);



System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();

cmd.CommandType = System.Data.CommandType.Text;

string sql1 = Session["txtFirstName"].ToString();

string sql2 = Session["txtLastName"].ToString();

cmd.CommandText = "INSERT dbo.Member (mbrFirstName, mbrLastName) VALUES (sql1, sql2)";

cmd.Connection = sqlConnection1;

sqlConnection1.Open(); //EXCEPTION HERE!!!

cmd.ExecuteNonQuery();

sqlConnection1.Close();

View 26 Replies View Related

Could Not Open A Connection To SQL Server

Nov 25, 2007

Hi, Has somebody had a problem like this before? Exception Details: System.Data.SqlClient.SqlException:
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) That's part of the code:        SqlConnection con;        string sql;        SqlCommand cmd;               con=new SqlConnection("Data Source=elf/SQLEXPRESS;Initial Catalog=logos;Integrated Security=SSPI;");        sql="SELECT max(id_kandydat) from Kandydat";        con.Open();         cmd=new SqlCommand(sql,con);        int id = Convert.ToInt32(cmd.ExecuteScalar());        con.Close();         SqlDataSource7.InsertCommand="INSERT INTO Kandydat_na_Kierunek(id_kandydat, id_kierunku, id_stan) VALUES ("+"'"+id+"'"+","+"'"+DropDownList1.SelectedValue+"'"+","+'1'+");";  I don't really get it. I'm nearly 100% sure that before some changes in my project this had worked perfectly. Does anybody have any idea how to make it work again? I would be very grateful for any help. And, yesy, I know it is quite common error, but proposed solution found didn't help.Regards,N.  

View 5 Replies View Related

Leave DB Connection Open

Mar 20, 2008

Hello, I have always closed my db connections asap after opening them and have always thought this was the best practice.  But now I am wondering if I can just leave the connection open.
I created a windows service which runs on a timer and executes every 5 seconds.  The problem is that the code takes longer than that to process and the code may be executing three times at once. Im worried that since I use the same connection each time the code executes that a connection opened by the first run through may be closed or reopened by the second or third running of the code resulting in an error.  The connection is opened and closed about 10 times each time the timer event fires.  Should I open the connection once and leave it open when the service is started and close it when it is stopped or on any error?
 
Thanks

View 2 Replies View Related







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