Dear friends,
plz help to solve my problem.
I want to place the database connection string in a text file
and i want to read the text from windows form of c#.
the connection string in a text file named "server.txt" is as follows
Data Source=MADHU\\SQLEXPRESS;Initial Catalog=GSTNDB;User ID=sa;Password=admin123
my code in the button click is
On executing it showing the error message.......
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL
If I use the same connection string as static value it is working fine, but if i read the text file it showing
the above error message.
thanks and regards
Madhu
plz help to solve my problem.
I want to place the database connection string in a text file
and i want to read the text from windows form of c#.
the connection string in a text file named "server.txt" is as follows
Data Source=MADHU\\SQLEXPRESS;Initial Catalog=GSTNDB;User ID=sa;Password=admin123
my code in the button click is
private void button1_Click(object sender, EventArgs e)
{
string Conn;
string connetionString = null;
SqlConnection connection;
SqlDataAdapter adapter;
SqlCommand command = new SqlCommand();
DataSet ds = new DataSet();
string srv = System.IO.File.ReadAllText(@"d:server.txt");
connetionString = srv;
connection = new SqlConnection(connetionString);
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "gst_proc";
adapter = new SqlDataAdapter(command);
adapter.Fill(ds);
}
On executing it showing the error message.......
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL
If I use the same connection string as static value it is working fine, but if i read the text file it showing
the above error message.
thanks and regards
Madhu
Last edited by a moderator: