Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i specified the connection string and my file path in app.config like this


<configuration>
<connectionstrings>
<add name="nConnectionString">
connectionString ="Data Source=CSZ-PCS43132\SQLEXPRESS;Initial Catalog=test;Integrated Security=True"
providerName="System.Data.SqlClient"/>


<appsettings>
<add key="empdetails" value="~/C:/Documents and Settings/aj99823/Desktop/project/Employee Details.txt">



and in the front end i called them as

public void employeedetails()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["nConnectionString"].ConnectionString);
// using (SqlConnection connection = new SqlConnection(str))
{
try
{
conn.Open();
}
catch (System.Data.SqlClient.SqlException ex)
{
return;
}
string selectCommandText = "SELECT distinct userid,fullname,lastname,firstname,localjobtitle,employmentstatusid,dateofjoining,dateofexit,siteid,email,topfunctionid,active,exitingthecompany,lmsroleid,locallanguagejobtitle FROM tblUserProfile up,tblreportingto tr,tblCountry where temo is null";
using (SqlDataAdapter adpSQL = new SqlDataAdapter(selectCommandText, conn))
{
using (DataTable table = new DataTable("tblUserProfile"))
{
adpSQL.Fill(table);
StringBuilder commaDelimitedText = new StringBuilder();
//commaDelimitedText.Append("EMP_Number|Name|Lastname|Firstname|Middleinitial|NameSuffix|Positiontitle|EMPcode|EMPstatus|Manager number|Approvernumber|Startdate|Enddate|Lastreviewdate|Address1|Address2|City|State|Zipcode|Country|Email|Phone1|Phone2|Fax|URL|Note|DomainCode|Organizationcode|Jobcode|Active|Enabled|Username|NTlogin|Role|Timezone|Currency|Language|Text1|Text2|Text3|Text4|Memo1|Date1|Date2|Indicator1|Money1|Integer1|Float1|JobJoiningdate|Organizationjoiningdate");
foreach (DataRow row in table.Rows)
{
string value = string.Format("{0}|{1}|{2}|||{3}||{4}|{5}||||||{6}||{7}|{8}|{9}||||||||{10}|{11}|{12}|{13}|", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14]);
commaDelimitedText.AppendLine(value);
}
File.AppendAllText(ConfigurationManager.AppSettings["empdetails"], commaDelimitedText.ToString());
}
}
}
}


But it is throwing error saying failed to initialize the connection.

if i put the just after the my connection string will get initialized successfuly but it will throw error where i specified the file path.....that is the following line...

File.AppendAllText(ConfigurationManager.AppSettings["empdetails"], commaDelimitedText.ToString());

can anyone please help me?????????????
Posted
Updated 7-Mar-12 0:15am
v2

1 solution

Firstly, check that you are reading it back correctly: read it into a string, and either log it to a file, or look at it in the debugger. Make sure that what you read back is what you think you wrote!

If that is ok, then check the string is a valid connection. Look at the connection to the same database in VS via the Server Explorer pane. Are they the same?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900