When ASP application is published to IIS using LocalDB accessing the database may result in the following error:
Server Error in '/Application_Name' Application.
<i>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: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
An easy solution to fix this error is to set IIS Application pool Process Model Identity to Local System.
Do not forget also to copy the database to appropriate directory on the same host where IIS is running and to set corresponding path in project Build -> Publish -> Settings -> ApplicationDBContext (DefaultConnection). Use “…” browse button to easy set all database connection properties.
The creation of custom control using Visual Studio involves the following steps:
1) Start Visual Studio;
2) Create new “Windows Control Library” project;
3) In the created project delete “User Control” file;
4) Go to “Project” > “Add User Control” and give it a name;
5) Change the inherited class to this that you want your control to be;
6) Create you custom properties for the control;
7) Compile the project: Go to “Build” > “Build Solution”;
8) The generated DLL file is located in you projects folder under:
“bin/Debug/UserContolName.dll” or “bin/Release/UserContolName.dll”.
That depends on how your solution is configured: “Debug mode” or “Release mode”.
Once created the DLL file can be added as custom control to Visual Studio toolbox.
This example shows how to create custom text box control which accepts only numbers, decimal separator or negative sign.
By default the text box only accepts numbers: 0123456789, to be entered.
There are two properties that allows the user to enter only numbers with decimal separator or signed numbers.
If both properties are enabled then the text box accepts numbers, decimal separator and negative sign.
A tool tip is shown with information what the user can enter in the text box, if incorrect data is tried to be entered.
A placeholder (watermark) functionality is added using the paint event of the text box.
Continue reading “C# Custom control – TextBox accepting only numbers, decimal numbers, signed numbers”
To add a custom control to VisualStudio project:
1) Go to “Toolbox” tab;
2) Right click on it and click “Choose Items…”;
3) In the “Choose Toolbox Items” window click on the “Browse…” button.
Navigate to the location where your Dynamic Link Library (DLL) file is.
Click “OK”. Now your custom control is included into the Visual Studio toolbox.
For example of how to create custom control with C# and Visual Studio read this article:
C# Custom control – TextBox accepting only numbers, decimal numbers, signed numbers.