Skip to main content
added 417 characters in body
Source Link

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

namespace rsDeployer.Common.SQLServerCommunication { public class RSDatabaseConnectionCreator: LoggerBase { public RSProfile profile; public RSDatabaseConnectionCreator(RSProfile profile) { this.profile = profile; } public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false) { var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication); if (testConnection) { return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null; } return new SqlConnection(connectionString); } } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
IfEdit 1 - class I would like to have it injected to.

 public void QueryExecution(string SQLQuery) { //here's where I would like to inject it SqlCommand command = new SqlCommand(SQLQuery, conn); var file = new StreamWriter(@"D:\Project\rsDeployer\ImportedQuery.txt"); file.WriteLine(command); file.Close(); } 

If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

namespace rsDeployer.Common.SQLServerCommunication { public class RSDatabaseConnectionCreator: LoggerBase { public RSProfile profile; public RSDatabaseConnectionCreator(RSProfile profile) { this.profile = profile; } public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false) { var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication); if (testConnection) { return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null; } return new SqlConnection(connectionString); } } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

namespace rsDeployer.Common.SQLServerCommunication { public class RSDatabaseConnectionCreator: LoggerBase { public RSProfile profile; public RSDatabaseConnectionCreator(RSProfile profile) { this.profile = profile; } public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false) { var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication); if (testConnection) { return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null; } return new SqlConnection(connectionString); } } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
Edit 1 - class I would like to have it injected to.

 public void QueryExecution(string SQLQuery) { //here's where I would like to inject it SqlCommand command = new SqlCommand(SQLQuery, conn); var file = new StreamWriter(@"D:\Project\rsDeployer\ImportedQuery.txt"); file.WriteLine(command); file.Close(); } 

If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

code formatting
Source Link
Nino
  • 7.1k
  • 2
  • 29
  • 46

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

 namespace rsDeployer.Common.SQLServerCommunication {  public class RSDatabaseConnectionCreator: LoggerBase  {   public RSProfile profile;   public RSDatabaseConnectionCreator(RSProfile profile)   {   this.profile = profile;   }   public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false)   {   var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication);   if (testConnection)   {   return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null;   }   return new SqlConnection(connectionString); } } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

 namespace rsDeployer.Common.SQLServerCommunication { public class RSDatabaseConnectionCreator: LoggerBase { public RSProfile profile; public RSDatabaseConnectionCreator(RSProfile profile) { this.profile = profile; } public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false) { var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication); if (testConnection) { return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null; } return new SqlConnection(connectionString); } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

namespace rsDeployer.Common.SQLServerCommunication {  public class RSDatabaseConnectionCreator: LoggerBase  {   public RSProfile profile;   public RSDatabaseConnectionCreator(RSProfile profile)   {   this.profile = profile;   }   public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false)   {   var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication);   if (testConnection)   {   return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null;   }   return new SqlConnection(connectionString); } } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.

Source Link

How to call object from one class to another in C#

I have a problem that I just can't solve on my own. I am new to programming and I would appreciate if you could help me with this issue:
I have a class I would like to inherit from:

 namespace rsDeployer.Common.SQLServerCommunication { public class RSDatabaseConnectionCreator: LoggerBase { public RSProfile profile; public RSDatabaseConnectionCreator(RSProfile profile) { this.profile = profile; } public SqlConnection CreateConnection(RSDatabaseNames DatabaseName, bool UseWindowsAuthentication, bool testConnection = false) { var connectionString = BuildRSDatabaseConnectionString(DatabaseName, UseWindowsAuthentication); if (testConnection) { return IsConnectionAvailable(connectionString) ? new SqlConnection(connectionString) : null; } return new SqlConnection(connectionString); } } 

and I would like to call CreateConnection() in another class to inject to methods to allow me to open connection and then execute scripts.
If this question is way to silly to deserve answer would you just point in the direction where I should read about it?

I hope this question is well asked and clear. Thanks in advance.