|
My Connection string :
<add name="CostAllocationEntities2" connectionString="Data Source=PC210090\SQLEXPRESS;Initial Catalog=testdb2;Persist Security Info=True;User ID=sa;password=password-1" providerName="System.Data.SqlClient"/>
|
|
|
|
|
Well the connection string format looks fine.
There could still be quite a few things causing the problem.
1. Are your sure the PC210090 name is correct?
2. Is SQLEXPRESS correct or are you using a named instance?
3. Is the DB name correct?
4. Is the username correct?
5. is the password correct?
If you have SQL Management Studio installed on your machine, can you connect to the database from there using the username and password?
In Visual Studio, try creating a connection from the Server Explorer window.
Is PC210090 where the db server is located the same machine you are using? It could be a firewall issue.
There are really quite a few reasons as to why its could not be working.
Neill
|
|
|
|
|
Another thing that I am confused by (which happens far too easily.) is if you are using a specific framework?
Why create ServerConnection with the specified ConnectionString which specifies the initial database, and then attempt sqlServer.Databases[strDBName] which is the database name passed into the method?
Neill
|
|
|
|
|
I can download small size of application but could not download big size of application. It shows out of memory.
Below is my code:
string Files = ListBox1.SelectedValue;
byte[] fileBytes = System.IO.File.ReadAllBytes(Files);
WebClient User = new WebClient();
byte[] FileBuffer = User.DownloadData(Files);
if (FileBuffer != null)
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-length", FileBuffer.Length.ToString());
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(Files));
context.Response.BinaryWrite(FileBuffer);
context.ApplicationInstance.CompleteRequest();
Could pls anyone help...
|
|
|
|
|
Member 12016106 wrote: byte[] fileBytes = System.IO.File.ReadAllBytes(Files); Do not assume that there is enough memory to hold the entire file.
|
|
|
|
|
So how should declare it to download large size file??
|
|
|
|
|
Simply put, computers don't have unlimited memory. Determine a reasonable buffer size and read the file in chunks of that size, processing each one in turn.
If your data has any kind of structure (either fixed size blocks, or flexible e.g. XML) you should make use of that to work out how to read and process it in smaller pieces.
I can't tell from your sample code what you're trying to do, but it appears you're accessing both local and remote files, either of which could be much larger than your available memory. You need to think through what processing you need to do, and how to achieve it within the limits.
Days spent at sea are not deducted from one's alloted span - Phoenician proverb
|
|
|
|
|
You have several options:
TransmitFile is the preferred method:
string physicalPath = ListBox1.SelectedValue;
if (!string.IsNullOrWhiteSpace(physicalPath))
{
FileInfo fileToSend = new FileInfo(fileToSend);
if (fileToSend.Exists)
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-length", fileToSend.Length.ToString());
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlPathEncode(fileToSend.Name));
context.Response.TransmitFile(fileToSend.FullName);
context.Response.Flush();
context.ApplicationInstance.CompleteRequest();
}
}
WriteFile will work in the same way, but can have problems with large files[^].
Reading the file in small blocks requires more code, and won't perform as well as TransmitFile :
int bytesRead;
byte[] buffer = new byte[10000];
using (Stream fileStream = fileToSend.OpenRead())
{
while (context.Response.IsClientConnected && (bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
context.Response.OutputStream.Write(buffer, 0, bytesRead);
context.Response.Flush();
}
}
context.ApplicationInstance.CompleteRequest();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
I am learning to develop in C # on my own which is not an easy thing.
I try to dynamically generate a name for answer my objects.
example:
ComboBox myCombo1 = new ComboBox ();
AND
myCombo1.Text = "Blabla";
What I would like is generated dynamically (myCombo1, myCombo2, myCombo3)
Is this possible or is there a class my question?
Thank you in advance for your help.
Alexandre
|
|
|
|
|
A simple way to do this is to define a Method that creates the ComboBoxes and automatically adds the identifier to their Name. Like this:
private static int ComboBoxCounter = 0;
private const string ComboBoxNameBase = "ComboBox";
public List<ComboBox> TheComboBoxes = new List<ComboBox>();
public ComboBox GetNewComboBox()
{
ComboBox cmbx = new ComboBox {Name = string.Format("{0}{1}",ComboBoxNameBase, ComboBoxCounter++)};
TheComboBoxes.Add(cmbx);
return cmbx;
}
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Thank you very mutch.
You know Telerik Framework?
I need help to develop a dynamic desktop with this Framework leaning on a SQL Database
|
|
|
|
|
I have dynamically created textboxes in a loop, and given them names at creation time.
txtProdName.Name = "txtProdName" + i;
pn.Controls.Add(txtProdName);
txtProdDesc.Name = "txtProdDesc" + i;
pn.Controls.Add(txtProdDesc);
The above snippet works fine. Controls are created, and removed as needed.
Now, I would like to go back and read or write information into these textboxes, but I'm at a lost as to how to address them.
I'm trying to do something like:
txtProdName + i.Text = "Blah";
txtProdDesc + i.Text = "Blah2";
Now I know the above code won't work, but wondering if there is someway to do something similar? Or am I totally barking up the wrong tree.
Thanks in advance.
P.S. I haven't found an answer to this anywhere, which leads me to believe I'm at the wrong tree.
|
|
|
|
|
There are several ways to do that - but the easiest is probably to use Controls.Find:
TextBox tbProd = (TextBox)pn.Controls.Find("txtProdName" + i, false).FirstOrDefault();
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ok, so I follow what you did with the code. Having difficulty in taking it to the next step.
My thoughts are, I should now be able to:
tbProd.Text = "Blah";
However, I get the following error:
'System.NullReferenceException'in Project.exe ("Object reference not set to an instance of an object.")
And to make sure I really do understand what you suggested:
TextBox tbProd = (TextBox)pn.Controls.Find("txtProdName" + i, false).FirstOrDefault();
Creating a new instance of a textbox, called tbProd that is being set to the first control found in the panel, pn with a name of txtProdName + i, and casting that to type textbox.
If I truly understand your code, and the error, it would appear that tbProd didn't actually get the copy I thought it did??
I truly want to thank you for your help.
|
|
|
|
|
The FirstOrDefault method returns null if the collection of objects returned by Find has no elements: so use the debugger to look at the Panel.Controls collection and see exactly what it contains - I suspect that it doesn't have anything, in which case you need to look at the environment in which you are calling Find. When are you doing it, what else have you done, that kind of thing. We can't do that for you - we don't have access to your code!
And BTW:
TextBox tbProd = .... Doesn't create a new instance - it creates a variable that can reference an instance. It's a small but very, very important distinction!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The WinForms ControlCollection does allow you to use a string Key to access members:
pn.Controls["txtProdName3"].Text = "hello"; When you set the 'Name property of a WinForm Control, you have created the Key (why MS documentation calls it a 'Key baffles me).
So, that is a way you could access the run-time created TextBoxes without keeping a direct reference to them in some data structure.
However, I strongly advise you not to rely on that, and suggest you do something like this:
public List<TextBox> ListOfTextBoxes = new List<TextBox>();
public void createTextBoxes(int howMany)
{
TextBox txtProdName;
TextBox txtProdDesc;
for(int i = 0; i < howMany; i++)
{
txtProdName = new TextBox();
txtProdDesc = new TextBox();
ListOfTextBoxes.Add(txtProdName);
ListOfTextBoxes.Add(txtProdDesc);
txtProdName.Name = "txtProdName " + i;
pn.Controls.Add(txtProdName);
txtProdDesc.Name = "txtProdDesc " + i;
pn.Controls.Add(txtProdDesc);
}
}
ListOfTextBoxes[2].Text = "blah";
pn.Controls["txtProdName3"].Text = "hello";
string tbContent1 = ListOfTextBoxes[0].Text; But, if you are going to use the Index to access the TextBoxes, you can see immediately that you'll have to remember which index to use for TextBoxes that are 'txtProdDesc, and which to use for 'txtProdName.
To make the code clearer, I would use two separate Lists. I would also consider using two Dictionaries of Type <string, TextBox>
If the two TextBoxes are designed to function as a "pair;" I'd consider another data structure, or consider creating a custom UserControl ... all depends on your Application and its scope, purpose, run-time load, etc.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 15-Oct-15 14:53pm.
|
|
|
|
|
Gentlemen,
I wanted to thank you for your help. Both of you got me going again.
|
|
|
|
|
I have a project that I have on TFS online. When Im trying to build the project, I get the following error:
Severity Code Description Project File Line Error The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\Users\Bryan\Source\Workspaces\TestProject\ContosoUniversity\packages\Microsoft.Net.Compilers.1.0.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'file:///C:\Users\Bryan\Source\Workspaces\TestProject\ContosoUniversity\packages\Microsoft.Net.Compilers.1.0.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll' or one of its dependencies. Could not find the file. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. ContosoUniversity
Has this something to do with that Azure don't support ASP.NET 4.6?
|
|
|
|
|
Hi all.
I have a problem. really need some help.
I have a form contains 2 usercontrols name: usercontrol 1 and usercontrol 2. I use System.Timers.Timer.Elapsed to redraw usercontrol 1 and usercontrol 2 follow interval(interval of usercontrol 1 = 100ms. interval of usercontrol 2 = 1000ms). I measure time to draw usercontrol 1 and usercontrol 2 and I realize that time to draw usercontrol 1 is increase when usercontrol 2 has been drawing, when usercontrol 2 complete, time to draw usercontrol 1 is decrease. Is there anyway to solve it(time to draw usercontrol 1 is stable, it's not depend on the drawing usercontrol 2).
modified 14-Oct-15 23:20pm.
|
|
|
|
|
Why are you using a timer to re-draw ? Is this a game ?
Normally, if there's custom drawing being done in a UserControl (or other container), this is done by using the 'Paint event.
Please tell us what your goal is here. Is there any dependency (like accessing the same Database) between the two UserControls ? Are both of the UserControls instances of the same UserControl Object, or do they both inherit from a common Class or Interface ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
I create a usercontrol name: panel1, use timer.Elapsed += OnTimerTick; OnTimerTick will call draw a function. I add 2 panel1 name: panel11 and panel12 into a form. usercontrol 1 draw into panel11, usercontrol 2 draw into panel12.
modified 15-Oct-15 4:33am.
|
|
|
|
|
Hi, You still haven't answered the question about why you are using Timers to control painting/drawing, and what it is your painting/drawing. Please be specific.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
I want to redraw usercontrol 1 and usercontrol 2 follow cycle(usercontrol 1 and usercontrol 2 always redraw follow Timer.Interval of each control), so I use Timer.Elapsed event to do that.
It draws line, text, ...
Sorry for bad English.
|
|
|
|
|
Perhaps if you could show us a cut down version of the paint code for both controls.
|
|
|
|
|
usercontrol 1 will invoke 2 functions, one of it:
public void DrawControl(Graphics g)
{
int X = 599;
int Y = 10;
int Width = 225;
using (GraphicsPath path = GraphicsHelper.Create(X, Y, 224, 119, 5))
{
using (Pen frameWithBlackBgrd = new Pen(CWColors.FrameWithBlackBgrd))
{
g.DrawPath(frameWithBlackBgrd, path);
}
}
if (GuiResInfoMng.Instance.Lang != null && GuiResInfoMng.Instance.Param != null)
{
using (SolidBrush fixedTextWithBlackBgrd = new SolidBrush(CWColors.FixedTextWithBlackBgrd))
{
g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS_COM_TOTALCNT),
FontFactory.Instance.GetFont(LangId.FNT_M2), fixedTextWithBlackBgrd, X, Y);
g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS_COM_PASS), FontFactory.Instance.GetFont(LangId.FNT_M2),
fixedTextWithBlackBgrd, X, Y + 23);
g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS_COM_NG), FontFactory.Instance.GetFont(LangId.FNT_M2),
fixedTextWithBlackBgrd, X - 1, Y + 46);
}
}
using (SolidBrush variableText = new SolidBrush(CWColors.VariableText))
{
g.DrawString(ParamHelper.GetParamStr(ParamId.TOTALCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT_M2), variableText, X + Width - 60, Y);
g.DrawString(ParamHelper.GetParamStr(ParamId.PASSCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT_M2), variableText, X + Width - 60, Y + 23);
g.DrawString(ParamHelper.GetParamStr(ParamId.NGCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT_M2), variableText, X + Width - 60, Y + 46);
}
}
|
|
|
|
|