Sir,
I am using vs2012. I have to access connection string via separate class. As strirng should be placed inside separate class and through that class connection should be returned to code. I have searched for it and below I have got a code.
Class file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for MyConnection
/// </summary>
public class MyConnection
{
public static SqlConnection ConnectionStr()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Initial Catalog=10.345.10.201;Initial Catalog=mydb;Persist Security Info=True;User ID=user;Password=user@123; Max Pool size = 500; Pooling = True";
return conn;
}
}
code file:
SqlConnection conn = connectionCls.openConnection();
string insertStatement = @"INSERT INTO
reportFormDataTable VALUES(@reportID ) ";
SqlCommand insertCommand = new SqlCommand(insertStatement, conn);
try
{
conn.Open();
insertCommand.Parameters.AddWithValue("@reportID", reportID);
insertCommand.ExecuteNonQuery();
}
System.Data.SqlClient.SqlException (0x80131904): Login failed for user
This is what I am getting as error message.