VS 2003 to VS 2005 problems

R

Roy Gourgi

Hi,

I just installed VS 2005 Express with SQL Server and when I try to run the
code that was working with VS 2003 is no longer working. Is it not backward
compatible. What has changed. Below is my code.

TIA
Roy



using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

namespace testing

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

int lnSOBN=900;

int lnBN1=188;



string strConnection = "Server=(local);Integrated
Security=yes;database=royDB";

SqlConnection conn = new SqlConnection(strConnection);

string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0, @par1)
";



SqlCommand cmd = new SqlCommand(strInsert , conn);

SqlParameter parameter1 = new SqlParameter("@par0",SqlDbType.Int,32);

SqlParameter parameter2 = new SqlParameter("@par1",SqlDbType.Int,32);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}
 
N

Nicholas Paldino [.NET/C# MVP]

Roy,

"not working" isn't really an apt description of the problem. Is it a
runtime error, a compilation error?

Some more insight would be greatly appreciated.
 
R

Roy Gourgi

Hi Nicholas,

Sorry about not being more specific. It's not a compile time error, as I
have it compiles without errors. It is a runtime error "SqlException was
unhandled" and the details are:

System.Data.SqlClient.SqlException was unhandled
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)"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=20
LineNumber=0
Number=2
Server=""
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Connect(Boolean&
useFailoverPartner, Boolean& failoverDemandDone, String host, String
failoverPartner, String protocol, SqlInternalConnectionTds connHandler,
Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean
integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword,
Boolean redirectedUserInstance)
at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo, String
newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at testing.Class1.Main(String[] args) in
D:\CSRBC\SQLSample\SQLSample\Class1.cs:line 39
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




Thanks
Roy





Roy Gourgi said:
Hi,

I just installed VS 2005 Express with SQL Server and when I try to run the
code that was working with VS 2003 is no longer working. Is it not
backward compatible. What has changed. Below is my code.

TIA
Roy



using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

namespace testing

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

int lnSOBN=900;

int lnBN1=188;



string strConnection = "Server=(local);Integrated
Security=yes;database=royDB";

SqlConnection conn = new SqlConnection(strConnection);

string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0,
@par1) ";



SqlCommand cmd = new SqlCommand(strInsert , conn);

SqlParameter parameter1 = new SqlParameter("@par0",SqlDbType.Int,32);

SqlParameter parameter2 = new SqlParameter("@par1",SqlDbType.Int,32);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}
 
T

Thomas P. Skinner [MVP]

You need to enable named pipes. Go to SQL Server 2005 Configuration Manager
and under protocols enable named pipes. That should fix the problem.

Tom Skinner [C# MVP]

Roy Gourgi said:
Hi Nicholas,

Sorry about not being more specific. It's not a compile time error, as I
have it compiles without errors. It is a runtime error "SqlException was
unhandled" and the details are:

System.Data.SqlClient.SqlException was unhandled
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)"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=20
LineNumber=0
Number=2
Server=""
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Connect(Boolean&
useFailoverPartner, Boolean& failoverDemandDone, String host, String
failoverPartner, String protocol, SqlInternalConnectionTds connHandler,
Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean
integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword,
Boolean redirectedUserInstance)
at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String newPassword, SqlConnection owningObject, Boolean
redirectedUserInstance)
at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at testing.Class1.Main(String[] args) in
D:\CSRBC\SQLSample\SQLSample\Class1.cs:line 39
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




Thanks
Roy





Roy Gourgi said:
Hi,

I just installed VS 2005 Express with SQL Server and when I try to run
the code that was working with VS 2003 is no longer working. Is it not
backward compatible. What has changed. Below is my code.

TIA
Roy



using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

namespace testing

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

int lnSOBN=900;

int lnBN1=188;



string strConnection = "Server=(local);Integrated
Security=yes;database=royDB";

SqlConnection conn = new SqlConnection(strConnection);

string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0,
@par1) ";



SqlCommand cmd = new SqlCommand(strInsert , conn);

SqlParameter parameter1 = new SqlParameter("@par0",SqlDbType.Int,32);

SqlParameter parameter2 = new SqlParameter("@par1",SqlDbType.Int,32);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}
 
R

Roy Gourgi

Hi Tom,

It didn't work?

Roy

Thomas P. Skinner said:
You need to enable named pipes. Go to SQL Server 2005 Configuration
Manager and under protocols enable named pipes. That should fix the
problem.

Tom Skinner [C# MVP]

Roy Gourgi said:
Hi Nicholas,

Sorry about not being more specific. It's not a compile time error, as I
have it compiles without errors. It is a runtime error "SqlException was
unhandled" and the details are:

System.Data.SqlClient.SqlException was unhandled
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)"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=20
LineNumber=0
Number=2
Server=""
State=0
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Connect(Boolean&
useFailoverPartner, Boolean& failoverDemandDone, String host, String
failoverPartner, String protocol, SqlInternalConnectionTds connHandler,
Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean
integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, SqlConnectionString connectionOptions, String newPassword,
Boolean redirectedUserInstance)
at
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, Object providerInfo,
String newPassword, SqlConnection owningObject, Boolean
redirectedUserInstance)
at
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, Object poolGroupProviderInfo, DbConnectionPool pool,
DbConnection owningConnection)
at
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at testing.Class1.Main(String[] args) in
D:\CSRBC\SQLSample\SQLSample\Class1.cs:line 39
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




Thanks
Roy





Roy Gourgi said:
Hi,

I just installed VS 2005 Express with SQL Server and when I try to run
the code that was working with VS 2003 is no longer working. Is it not
backward compatible. What has changed. Below is my code.

TIA
Roy



using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

namespace testing

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

int lnSOBN=900;

int lnBN1=188;



string strConnection = "Server=(local);Integrated
Security=yes;database=royDB";

SqlConnection conn = new SqlConnection(strConnection);

string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0,
@par1) ";



SqlCommand cmd = new SqlCommand(strInsert , conn);

SqlParameter parameter1 = new SqlParameter("@par0",SqlDbType.Int,32);

SqlParameter parameter2 = new SqlParameter("@par1",SqlDbType.Int,32);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}
 
R

Roy Gourgi

Ok I no longer get the runtime error with this connection string but it
still does not insert a record in my database. Here is the code.

using System;

using System.Data;

using System.Data.Common;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Text;

namespace testing

{

class Class1

{

[STAThread]

static void Main(string[] args)

{

int lnSOBN = 900;

int lnBN1 = 188;

string strConnection = @"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\royDB.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True";

SqlConnection conn = new SqlConnection(strConnection);

string strInsert = "INSERT INTO [tblRoy ] (SOBN, BN1) VALUES (@par0, @par1)
";



SqlCommand cmd = new SqlCommand(strInsert, conn);

SqlParameter parameter1 = new SqlParameter("@par0", SqlDbType.Int, 32);

SqlParameter parameter2 = new SqlParameter("@par1", SqlDbType.Int, 32);

parameter1.Value = lnSOBN;

parameter2.Value = lnBN1;

cmd.Parameters.Add(parameter1);

cmd.Parameters.Add(parameter2);

cmd.Connection.Open();

cmd.ExecuteNonQuery();

cmd.Connection.Close();

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top