check this
-
public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...
-
public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...
Please Don't Cross Post X|
cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net
-
public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...
I don't know if you can treat an arbitrary text as a database. A CSV-text, no problems. It kinda depends on the format of your textfile. Can you show us a small excerpt (5 lines), including escape-characters? Anyway, if you want to verify that your connection-string works and can connect to the datastore, invoke the function described below;
/// Used to determine whether we can connect to a db-instance as provided
/// By a connectionstring.
internal bool TryConnectToSqlInstance(string connectionString)
{
using (SqlConnection con = new SqlConnection(connectionString))
try
{
con.Open();
}
catch (SqlException ex)
{
MessageBox.Show(String.Format("{0}\n\nConnection string: '{1}'", Message, connectionString}
Application.ProductName,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
while (con.State == ConnectionState.Connecting)
Application.DoEvents();
if (con.State == ConnectionState.Open)
MessageBox.Show("Connection Succeeded!",
Application.ProductName,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}You might also be interested in this[^] link, where you can find various connectionstrings for almost every database.
I are troll :)
-
public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...
No, you cannot refer to the contents of the text file as the data source. Use config file or read the text from the textfile, for example using File.ReadAllLines[^] amd then place the contents to your connection string. Something like:
string[] datasource = File.ReadAllLines("D:\\king.txt");
string connection = "Provider=SQLOLEDB; Data Source="
+ datasource[0]
+ ";Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn";The need to optimize rises from a bad design.My articles[^]
modified on Thursday, January 22, 2009 12:15 PM
-
No, you cannot refer to the contents of the text file as the data source. Use config file or read the text from the textfile, for example using File.ReadAllLines[^] amd then place the contents to your connection string. Something like:
string[] datasource = File.ReadAllLines("D:\\king.txt");
string connection = "Provider=SQLOLEDB; Data Source="
+ datasource[0]
+ ";Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn";The need to optimize rises from a bad design.My articles[^]
modified on Thursday, January 22, 2009 12:15 PM
nice gentle man u got my problem... when i include those lines i get this error.... "File does Not exist in the current context"
-
nice gentle man u got my problem... when i include those lines i get this error.... "File does Not exist in the current context"
-
File class is under System.IO namespace, so you can refer to it like
System.IO.File.ReadAllLines(...
or addusing System.IO
directive to your file.The need to optimize rises from a bad design.My articles[^]
i got this error Could not find file 'D:\king.txt'. but i have word file in my d:
-
i got this error Could not find file 'D:\king.txt'. but i have word file in my d:
-
As the message says, the file cannot be opened. Re-chek the path and the name and if another application is having that file open, close the other application first.
The need to optimize rises from a bad design.My articles[^]
the file did not open any where in my project... i gave like this... string[] datasource = File.ReadAllLines("D:\\king.txt"); Could not find file 'D:\king.txt'. if i give like this.... string[] datasource = File.ReadAllLines("D:\king.txt"); Error 1 Unrecognized escape sequence //occurs i gave like this... string[] datasource = File.ReadAllLines("D:king.txt"); Could not find file 'D:\king.txt'.
-
the file did not open any where in my project... i gave like this... string[] datasource = File.ReadAllLines("D:\\king.txt"); Could not find file 'D:\king.txt'. if i give like this.... string[] datasource = File.ReadAllLines("D:\king.txt"); Error 1 Unrecognized escape sequence //occurs i gave like this... string[] datasource = File.ReadAllLines("D:king.txt"); Could not find file 'D:\king.txt'.
The problem isn't in your code, but the code cannot open the file from the operating system. Check (for example using windows explorer) that: - the file is on drive D and in the root directory - the file is named king.txt - you have privileges to open the file - the file isn't open in any program, for example in Microsoft Word etc.
The need to optimize rises from a bad design.My articles[^]
-
The problem isn't in your code, but the code cannot open the file from the operating system. Check (for example using windows explorer) that: - the file is on drive D and in the root directory - the file is named king.txt - you have privileges to open the file - the file isn't open in any program, for example in Microsoft Word etc.
The need to optimize rises from a bad design.My articles[^]
file read successfully but.. reading in this manner ::ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0\t\0\0\0ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0
-
file read successfully but.. reading in this manner ::ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0\t\0\0\0ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0
Are you sure it's a plain text file and not for example in Word format? Open it using notepad. It should answer that question. File-class reads the text as plain text. If the file contains some other format, File class is unable to "translate" it to text.
The need to optimize rises from a bad design.My articles[^]
-
Are you sure it's a plain text file and not for example in Word format? Open it using notepad. It should answer that question. File-class reads the text as plain text. If the file contains some other format, File class is unable to "translate" it to text.
The need to optimize rises from a bad design.My articles[^]
i typed "veeserv3" in that word doc... it is not empty... "Format of the initialization string does not conform to specification starting at index 0." this error also occured..
-
i typed "veeserv3" in that word doc... it is not empty... "Format of the initialization string does not conform to specification starting at index 0." this error also occured..
VERY VERY THANKS GENTLE MAN... I GOT THE RESULT...