I am trying to connect to Microsoft SQL Server on localhost. My code is as follows.
public SqlConnection con;
// To Handle connection related activities
private void connection()
{
string constr = ConfigurationManager.ConnectionStrings["Data Source = MACHINE-VOIV7EH\\SQLEXPRESS; Initial Catalog = geolog; Persist Security Info = False; "].ToString();
con = new SqlConnection(constr);
}
public List<Bob> GetAllBobs()
{
try
{
connection();
con.Open();
IList<Bob> EmpList = SqlMapper.Query<Bob>(con, "GetBobs").ToList();
con.Close();
return EmpList.ToList();
}
catch (Exception)
{
throw;
}
}
con return null
SQL Server settings:
Configuration from Pyton (try, but another database):
conn = pypyodbc.connect('DRIVER={SQL Server};'
r'SERVER=MACHINE-VOIV7EH\SQLEXPRESS;'
r'DATABASE=vibori;'
r' autocommit=True'
)
