|
Dave that worked I modified just a bit of the code and it worked out.
Thanks
|
|
|
|
|
Hi there i'm trying to read data from SQL
This is my Class
class Sql
{
public SqlConnection sqlCon;
public void connectToSql (string adr)
{
sqlCon = new SqlConnection(adr);
try
{
sqlCon.Open();
}
catch (Exception e)
{
string str = e.ToString();
using (StreamWriter sw = new StreamWriter ("out1.txt"))
{
sw.WriteLine (e.ToString());
}
}
}
public void readSql(String col, String tab)
{
try
{
SqlDataReader sqlRead = null;
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + tab + " WHERE Column =" + col, sqlCon);
sqlRead = sqlCmd.ExecuteReader();
using (StreamWriter sw = new StreamWriter ("out.txt"))
{
sw.WriteLine(sqlRead.ToString());
}
}
catch (Exception e)
{
using (StreamWriter sw = new StreamWriter ("out.txt"))
{
sw.WriteLine (e.ToString());
}
}
}
public void exitSql()
{
sqlCon.Close();
}
}
}
And this is the error that i get
System.Data.SqlClient.SqlException: 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 Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at longliveSorin.functiiSql.Sql.connectToSql(String adr) in D:\work\cte\C#\cifru\longliveSorin\longliveSorin\functiiSql\Sql.cs:line 19
Can someone help me plz
|
|
|
|
|
Could be your connection string, can you post it please
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
private Sql sql = new Sql();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String adr = @"Address=localhost;Initial Catalog=Cifru;connection timeout=10;";
sql.connectToSql(adr);
sql.readSql("NumePrenume","contacte");
sql.exitSql();
}
I tried it without the @ but it still didn't work
|
|
|
|
|
Looks like your connection syring is all wrong. Take s visit to connectionstrings.com/[^]
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Check if your connection string is correct. You can find all sorts of connection strings here[^].
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thank you i'll take a look
|
|
|
|
|
Hi,
There is a compiler switch to create pdb symbols in VC++. What needs to be done to create symbols for a C# app?
I couldn't find any setting in the project properties page. I have noticed that when I compile the project, it creates a pdb in
the debug/release folder.
MSDN says we can use csc /debug /pdb:tt t.cs to create PDB, but is there a way to create PDBs from the GUI?
Thanks in advance,
Nachiket
|
|
|
|
|
Yes, by compiling your code.
The file maps the binary back to the source-code, and is as such, dependent on the binary. Without the binary there is nothing to map.
|
|
|
|
|
Thanks Eddy.
So what kind of symbols are created when I compile the code? public or private?
I am looking for a way to create private symbols so that I can see source file and line number information from a crash dump through windbg.
|
|
|
|
|
I just copy them to the bin\debug-directory. You might be interested in this[^] article.
I are Troll
|
|
|
|
|
|
You're welcome
I are Troll
|
|
|
|
|
Hi all,
I know this is not a C# relating question, didn't found a better forum .... but I read
so much and I tried much more...
The problem: I compiled a .chm helpfile with a correct linked html-file-site structur.
Outside the .chm file everything works fine.
I used different tools and I came always to the same result - the contens side stays blank
(than means - the typical message ... there is no internet connection ....comes up)
I registered the .chm file in the registry and controled that.
I set the correct accesslevel in the registry to Nr. 2 (means that local rights are accepted)
I decompiled my .chm file to see that the html-files are realy included - all seems to be fine.
What more is to do that the .chm contens will be shown ???
Thanks
Regards,
Frank
|
|
|
|
|
I've seen issues like that crop up due to Privacy Settings in the Internet Options. Try adjusting those to be less restrictive and see what happens.
You might also try making sure your CHM is on your local computer's hard drive rather than on a networked drive. Just a few things to check out.
|
|
|
|
|
Thank's for your suggestions,
the .chm file was generated on the local computer and shall be opened there also.
Thanks
Regards, Frank
|
|
|
|
|
You say you have tried lots, so it is difficult to know what to suggest.
However I have had this problem a few times and it has always been #2 from this[^] that has caused my problems. If you haven't already done so can I suggest that you google for problem with chm file blank contents, there are lots of hits.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
there are realy some more suggestions to solve the problem. I will follow your links. Will see what will happen.
But i fear I can't deploy a .chm file with my application due to similar expected problems on the clients.
Isn't there a more reliable (local) help technology on the market than .chm ?
Thanks,
Regards, Frank
|
|
|
|
|
Hi,
I am using Windbg to analyze a crash that was created from managed code. I am loading SOS and mscorwks and using the !pe command. I can see the managed callstack, with module and function names but no source file and line number information. I can see this information for native crashes, but not for managed.
I don't know if it is the PDBs or something else. when I did lm, it says I have private pdb symbols for my managed app.
Any help is highly appreciated.
Thanks
Nachiket
|
|
|
|
|
All,
I am interested in developing servers like FTP, HTTP/HTTPS using Windows XP with IIS 5.1 version server. I have searched a lot on internet for pointers which will give me information for creating all these servers using C#, but everything went vain! . I would request this forums members to give some information on implementing all these 3 servers using C#.I appreciate your help
Thanks Rajesh
|
|
|
|
|
I turned on the autocomplete feature for a combobox on my form and set the autocompletesource to Listitems. It is a databound combobox. When the user selects an item using autocomplete, I don't get a value for selectedvalue, is this expected behavior? Do I have to write a Leave routine to match the text with the value from the combobox?
Shouldn't this behavior be automatic?
|
|
|
|
|
WinForms ComboBox es? I didn't see a SelectedValue property, but I did find a SelectedItem [^] that might help you out
I are Troll
|
|
|
|
|
Hello am adding days for a date Time object but it is not adding the valyes could any body know why, btw am checking the values in a watch they are not changing unless i change them there(Watch);
DateTime startDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
DateTime endDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
startDate.AddDays(-3);
endDate.AddDays(3);
DateTime x = new DateTime();
x=DateTime.Now;
x.AddDays(3);
|
|
|
|
|
DateTime is immutable. The AddDays function (and others) return a new DateTime, they don't alter the first one so you need
startDate = startDate.AddDays(-3);
etc...
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DateTime x = new DateTime();
x=DateTime.Now;
Also, in the second line you throw away the DateTime created in the first line, so why create it?
Try:
DateTime x ;
x=DateTime.Now;
or
DateTime x=DateTime.Now;
|
|
|
|