1
I have my class DadosConexao
, this class is responsible for storing the connection string of the database, it contains the following properties:
A statistical property StringConexao
.
isServ
indicates if you are a server or client.
servidor
keeps the name of the machine.
The problem is I can’t move the property StringConexao
, that in the case and the "Data Source="
a part of the string that would be the name of the machine that contains the database.
My class Dadosconexao:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAL
{
public class DadosConexao
{
private String servidor;
private Boolean isServ;
public DadosConexao(bool isServ, string servidor)
{
this.isServ = isServ;
this.servidor = servidor;
}
public static string StringConexao
{
get
{
if (!isServ)//Da erro aqui
servidor = Environment.MachineName.ToString();//Caso isServ for true pega o nome da maquina local.
return "Data Source=" + servidor +
"\\MINHAINSTANCIA;" +
"Initial Catalog=MINHABASE;" +
"Persist Security Info=True;" +
"User ID=sa;" +
"Password=123456";
}
}
}
}
Error presented by Visual Studio:
Error 1 An object reference is required
for the non-static field, method,
or property 'DAL.DadosConexao.isServ'
The system works as a client or server, if the client is the property servidor
is set in user settings.
tried to use
if (isServ == false)
?– CypherPotato
Yes, the problem of this class has been solved, and I’m using
if (isServ)
.– gato