I have my class DadosConexao
, this class is responsible for saving the connection string of the database, it contains the following properties:
A statistical property StringConexao
.
isServ
indicates whether it is a server or client.
servidor
save machine name .
The problem is that I can not change the StringConexao
property, which in this case and "Data Source="
is a part of the string that would be the machine name that contains the database .
My class ConnectionData :
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";
}
}
}
}
Visual Studio error:
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 client the servidor
property is defined in the settings by the user.