Setting up BugTracker.NET complete noob - connection-string

This is my first ASP.NET project and I'm stuck right away.
I'm setting up a bugtracker on a remote webhotel but I can't get the connectionstrings to work.
If we say that my host is called hosting.org and my website would be www.trallala.com
what do I have to change in this script?
<configSections>
</configSections>
<system.web>
<!--
BugTracker.NET is not compatible with Session serialization.
Timeout session after 120 minutes
-->
<sessionState mode="InProc" timeout="120"/>
<compilation debug="true">
<assemblies>
<add assembly="System.DirectoryServices.Protocols, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<pages validateRequest="true" />
<!-- A few people over the years have needed to override the default IIS settings...
<httpRuntime executionTimeout="300" maxRequestLength="51200"/>
-->
<!-- for my testing <globalization culture="de-DE" uiCulture="en-US" /> -->
</system.web>
<appSettings>
<!--
********* QUICK START *************
If you want to get started quickly, then just change the following
and then try to log in:
ConnectionString
AbsouteUrlPrefix
After you can log in and create a bug, then you probably want to
set up the email integration. Set up the following:
ErrorEmailTo
ErrorEmailFrom
NotificationEmailEnabled
NotificationEmailFrom
And your SMTP settings below.
-->
<!--
Change this to point to your database
-->
<add key="ConnectionString" value="server=(local)\SQLEXPRESS;database=btnet;user id=sa;password=x;Trusted_Connection=no"/>
<!--
Used when creating absolute href's. For example, in notification emails.
Don't forget trailing slash!.
-->
<add key="AbsoluteUrlPrefix" value="http://127.0.0.1/btnet2/"/>
<!--
You can turn the logging and emailing of errors on and off.
Log file name is "btnet_log_yyyy_mm_dd.txt"
For the LogFileFolder setting, if you specify the folder starting with a
drive letter or the \\ that indicates a UNC path, it's treated as a full path.
For example: c:\\something or \\somemachine\something
Otherwise it's treated as a path relative to where you virtual directory is
located.
LogEnabled turns on and off logging as a whole.
LogSqlEnabled turns on and off just the logging of SQL statements, but
that's about 98% of what gets logged, so if you want to reduce the
volume, turn that off.
-->
<add key="LogEnabled" value="1"/>
<add key="LogSqlEnabled" value="1"/>
<add key="LogFileFolder" value="App_Data\logs"/>
<!-- If BugTracker.NET itself experiences an error, it can send an email notification -->
<add key="ErrorEmailEnabled" value="1"/>
<add key="ErrorEmailTo" value="YOUR EMAIL HERE"/>
<add key="ErrorEmailFrom" value="FROM EMAIL HERE"/>
<!--
You can "subscribe" to email notifications on a per-bug basis.
You will receive an email whenever the bug is updated.
-->
<add key="NotificationEmailEnabled" value="1"/>
<add key="NotificationEmailFrom" value="FROM EMAIL HERE"/>
<!--
This controls the format of the subject of the email notifications.
The available variables are:
$THING$ - from the "SingularBugLabel" setting
$BUGID$
$ACTION$ - added or changed
$SHORTDESC$
$PROJECT$
$CATEGORY$
$ORGANIZATION$
$PRIORITY$
$STATUS$
$TRACKINGID$ - from the "TrackingIdString" setting
-->
<add key="NotificationSubjectFormat" value="$THING$:$BUGID$ was $ACTION$ - $SHORTDESC$ $TRACKINGID$"/>
<!--
If you aren't using the local SMTP server that comes with IIS,
set the name, user, and password for your SMTP server here.
-->
<!-- Sample SMTP Settings -->
<!--
These settings work with my SBC account
-->
<!--
<add key="SmtpServer" value="smtp.att.yahoo.com"/>
<add key="SmtpServerAuthenticateUser" value="ctrager#sbcglobal.net"/>
<add key="SmtpServerPort" value="465"/>
<add key="SmtpUseSSL" value="1"/>
<add key="SmtpServerAuthenticatePassword" value="MY PASSWORD"/>
-->
<!--
These settings work with my GMail account
-->
<!--
<add key="SmtpServer" value="smtp.gmail.com"/>
<add key="SmtpServerAuthenticateUser" value="ctrager#gmail.com"/>
<add key="SmtpServerPort" value="465"/>
<add key="SmtpUseSSL" value="1"/>
<add key="SmtpServerAuthenticatePassword" value="MY PASSWORD"/>
-->
<!--
These settings work with my GoDaddy account
-->
<!--
<add key="SmtpServer" value="relay-hosting.secureserver.net"/>
<add key="SmtpServerAuthenticateUser" value="ctrager#ifdefined.com"/>
<add key="SmtpServerAuthenticatePassword" value="MY PASSWORD"/>
<add key="SmtpServerPort" value="25"/>
-->
<!--
Specify the pickup directory if you have the problem described here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;816789#8
-->
<!--
<add key="SmtpServerPickupDirectory" value=""/>
<add key="SmtpSendUsing" value="1"/>
-->
<!--
Ignore this setting unless you are esperiencing the symptoms
related to this: http://cr.yp.to/docs/smtplf.html
-->
<!--
<add key="SmtpForceReplaceOfBareLineFeeds" value="1"/>
-->
<!--
By default, emails are UTF8 encoded. If that doesn't work for you,
uncomment the following.
-->
<!--
<add key="BodyEncodingUTF8" value="0"/>
-->

<add key="ConnectionString" value="Persist Security Info=true;User ID=bugtracker;Password=bugs;Initial Catalog=BugTracker;Data Source=[IP ADDRESS]" />
This is what you'd need to add/edit in the web.config. once it's setup, BugTracker will run the scripts to create the proper database elements.

You need to make sure that "ConnectionString" points to the right Database and has the right username and password for DB-access.
You might want to make sure that your Database is actually up and running and that the username and password are correct by simply trying to log in as that user in your DB.
If that doesn't work, than the problem doesn't lie with your asp.net configuration.

The BugTracker.NET documentation includes this section on connection strings:
The hardest part ...for most people is getting the ConnectionString to work.
For help, see these links, the "SqlConnection (.NET)" sections
http://www.connectionstrings.com/?carrier=sqlserver2005
http://www.sqlstrings.com/SQL-Server-connection-strings.htm
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-3513_11-6084879.html
Another thing you might try to get the connection string right is the following:
Create a new blank file and name it test.udl.
Double click on it, and a "Data Link Properties" dialog should appear.
On "Providers" tab, select "Microsoft OLE DB Provider for SQL Server" or "SQL Native Client"
On "Connections" tab, try various settings and use the "Test Connection" button to test them. Click "Ok" when it works.
Open the test.udl file in Notepad and copy the line that starts with "Provider=" into your Web.config "ConnectionString" value, BUT delete the little part that says "Provider=SQLNCLI.1;"

Related

Delete files older then X day.. BUT not by date modified

I have a config file for an .exe my workplace built where you can specify deleting of files (specifically retaining the last say 30 days files in my test here [logs and sql are fine]) and it even clears out sub folders. however it is deleting by date modified, so newer folders with some old remnents of data are getting the old remnents deleted.
Folder1:
File: Modified:
File 1 2018/02/02
File 2 2010/05/06
File 3 2018/02/01
Folder 2:
File: Modified:
File 1 2011/12/30
File 2 2006/01/16
File 3 2018/02/02
Would leave:
Folder1:
File: Modified:
File 1 2018/02/02
File 3 2018/02/01
Folder 2:
File: Modified:
File 3 2018/02/02
Is there anyway to change this so it retains the last 30 folders and contents,, deleting everything else?
This is the contents of the "cleaner".exe.config file I have:
<?xml version="2.0" encoding="utf-8"?> <configuration> <configSections> </configSections> <!-- Make sure that every new location has a name with an increasing number e.g clear 1 -->
<appSettings>
<add key="connstring" value="Data Source=localhost;user id = *****;password = *****;Initial Catalog =Database;" />
<add key="sqldays" value="180" />
<add key="LogLocation" value="C:\File\Logs\Cleaner\" />
<add key="clear" value="C:\Directory\Logs,90" />
<add key="clear2" value="C:\Directory\CSV\Backup,30 " />
<add key="fileExtensions" value=".txt,.csv,.log,.fmt,.hdr,.Log" />
<add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> </configuration>
Just to close this out it didnt matter about the modified date, the files just needed to 'be gone' so I added a few more directories to the config file and let it loose.
Example:
<?xml version="2.0" encoding="utf-8"?> <configuration> <configSections> </configSections> <!-- Make sure that every new location has a name with an increasing number e.g clear 1 -->
<appSettings>
<add key="connstring" value="Data Source=localhost;user id = *****;password = *****;Initial Catalog =Database;" />
<add key="sqldays" value="180" />
<add key="LogLocation" value="C:\File\Logs\Cleaner\" />
<add key="clear" value="C:\Directory\Logs,90" />
<add key="clear2" value="C:\Directory\CSV\Backup,30 " />
<add key="clear3"value="C:\Directory1\CSV\Backup,30 " />
<add key="clear4" value="C:\Directory2\CSV\Backup,30 " />
<add key="fileExtensions" value=".txt,.csv,.log,.fmt,.hdr,.Log" />
<add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> </configuration>

Can't insert into SQL Server table with log4net AdoNetAppender

I am trying to understand how log4net works so I've added this to my app.config (I should add that Console Appender and FileAppender work perfectly, I only have trouble with the AdoNetAppender).
How can I debug this, to see if at least the connection to db succeeds?
The problem is the INSERT statement isn't executed.
I should add the
Data Source=MyWorkgroup\SQLEXPRESS;Initial Catalog=MyNewDatabase;User ID=juan;password=juan,
works perfectly when I try to connect to SQL Server manually, so not sure if that's the problem.
Also, the ConnectionType was taken from the official site:
https://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Appender.AdoNetAppender.ConnectionType.html
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.log4netConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="AdoNetAppender"
type="log4net.Appender.AdoNetAppender">
<bufferSize value="10" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=MyWorkgroup\SQLEXPRESS;Initial Catalog=MyNewDatabase;User ID=juan;Password=juan;Pooling=False" />
<commandText value="INSERT INTO Logs([logDate],[logThread],[logMessage]) VALUES(getdate(),'1','1')" />
<commandType value="Text" />
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="AdoNetAppender"/>
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Later edit (after using the debug method recommended by David):
haacked.com is indeed extremely interesting, great tip! However, it seems that it's describing what I'm instructing log4net to log, but not the result of those actions(?), if I'm reading this well (no failed/or succeeded?)
e.g.
log4net: Setting Property [ConnectionType] to String value
[System.Data.SqlClien t.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToke n=b77a5c561934e089]
log4net: Setting Property [ConnectionString] to String value [Data
Source=MyWorkgroup\SQLEXPRESS; Initial
Catalog=MyNewDatabase;
User ID=juan; Password=juan;
Pooling=False] log4net: Setting Property [CommandText] to String value [INSERT INTO Logs([logDate],[logThread],[logMessage]) VALUES(getdate(),'1','1')] log4net:
Setting Property [CommandType] to CommandType value [Text] log4net:
Created Appender [AdoNetAppender] log4net: Adding appender named
[AdoNetAppender] to logger [root]. log4net: Hierarchy Threshold []
Piece of code that helped me obtain this info (in case the site should become unavailable) is:
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\temp\log4netdiagn.txt" />
</listeners>
</trace>
</system.diagnostics>

Unable to cast object of type 'System.Web.Security.SqlRoleProvider' to type 'WebMatrix.WebData.SimpleRoleProvider'

I developing an mvc web app with Entity Frame]work. I've enabled database migration so that i can add some seed data on each update.
More specifically, i want to add two users and two roles; so the configuration file looks like this:
var roles = (SimpleRoleProvider)Roles.Provider;
var membership = (SimpleMembershipProvider)Membership.Provider;
//// create two roles
if (!roles.RoleExists("Admin"))
{
roles.CreateRole("Admin");
}
if (!roles.RoleExists("User"))
{
roles.CreateRole("User");
}
However there seems to be a problem during the casting; it throws an exception
Unable to cast object of type 'System.Web.Security.SqlRoleProvider' to type 'WebMatrix.WebData.SimpleRoleProvider'.
I suspect that this might be a configuration issue, but i'm not really sure. Does anyone stumbled across the same problem?
That's because SqlRoleProvider does not inherit SimpleRoleProvider. However, you can try using SimpleRoleProvider Constructor (RoleProvider):
var roles = new SimpleRoleProvider(Roles.Provider);
I sorted this out. The problem apparently was related to web configuration. I added the following lines to the web.config file:
<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
<providers>
<add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
to explicitly set the role provider. So now the Roles.Provider returns an instance of WebMatrix.WebData.SimpleRoleProvider; thus i don't need to cast any more
I solved this by placing below code in web.config between
<roleManager enabled="true" defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
<membership defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>

MVC 4 - after seeding database webpages_Roles is still empty

So I have basic MVC 4 Internet application project with Entity Framework 5.
I have configured WebSecurity that uses my table for users.
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "Email", autoCreateTables: true);
Then in my migration configuration class I seed DB with new roles and add users to them.
internal sealed class Configuration : DbMigrationsConfiguration<Infrastructure.KlepecV2Db>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Infrastructure.KlepecV2Db context)
{
if(!Roles.RoleExists("Admin"))
{
Roles.CreateRole("Admin");
}
if (!Roles.RoleExists("Test1"))
{
Roles.CreateRole("Test1");
}
if(Membership.GetUser("user1") != null)
{
if(!Roles.IsUserInRole("user1","Admin"))
{
Roles.AddUserToRole("user1", "Admin");
}
}
if (Membership.GetUser("user2") != null)
{
if (!Roles.IsUserInRole("user2", "Admin"))
{
Roles.AddUserToRole("user2", "Admin");
}
}
}
}
So when I type "update-database" in NuGet console everything gets executed without errors. But if I look into webpages_Roles table its empty. Also webpages_UsersInRoles is empty.
For testing I have removed Role.RoleExists() calls and updating database fails, becouse roles already exists.
What am I missing here? Where are this roles stored?
I came across into an error The Role Manager feature has not been enabled mentioned by #Magnus. Hope this probably related to your roles issue in which the default role provider is unknown.
The error The Role Manager feature has not been enabled happened when I move the WebSecurity.InitializeDatabaseConnection method from MVC project into a class library (data access) for code first migration seed.
The point is App.config need to be configured for Package Manager Update-Database command to be run just like when Web.config exist.
Below is my App.config and Seed. Note that
I add "DefaultConnection" connection string *
Add system.web->roleManager to set the enable="true"
Add runtime->assemblyBinding->qualifyAssembly to give hint to compiler where is WebMatrix.WebData by giving the full assembly name.
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Db;Persist Security Info=True;User=user;Password=pass" providerName="System.Data.SqlClient" />-->
</connectionStrings>
<system.web>
<roleManager enabled="true" defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
</providers>
</roleManager>
<membership defaultProvider="simple">
<providers>
<clear />
<add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="WebMatrix.WebData" fullName="WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
Seed Method:
protected override void Seed(DatabaseContext context)
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "Id", "Email", autoCreateTables: true);
if(!Roles.RoleExists("Admin"))
{
Roles.CreateRole("Admin");
}
if (!Roles.RoleExists("Test1"))
{
Roles.CreateRole("Test1");
}
if(Membership.GetUser("user1") != null)
{
if(!Roles.IsUserInRole("user1","Admin"))
{
Roles.AddUserToRole("user1", "Admin");
}
}
if (Membership.GetUser("user2") != null)
{
if (!Roles.IsUserInRole("user2", "Admin"))
{
Roles.AddUserToRole("user2", "Admin");
}
}
}
Hope this will help anyone with The Role Manager feature has not been enabled issue when using code first migration seed in a class library.
Update
* EF5 will read the connection string in Web.config of Mvc project but not in the App.config of the project with EF Migrations. However the membership and roleManager settings is still required in the EF Migration project.
Wanted to add my $0.02 to the conversation. I have a similar setup to CallMeLaNN, but was still getting the error. My solution was to set my "Data" project to a StartUp project. After that, my app.config file started getting picked up, and I can now seed my users from the Update-Database command.

How do I read a custom section in app.config from codebehind?

I have an app.config file that stores values in a few different sections. I have these snippets:
<configuration>
<configSections>
<sectionGroup name="someDataAccessLayer">
<section name="databaseConnectionStrings" type="sometype" />
</sectionGroup>
</configSections>
<someDataAccessLayer>
<databaseConnectionStrings>
<databaseConnectionString name="someSQL"
value="database=somedatabase;Integrated Security=False;User Id=sa;server=someserver;Password=somepassword/>
</databaseConnectionStrings>
</someDataAccessLayer>
How do I read the connection string in the codebehind? Specifically the value which is
database=somedatabase;Integrated Security=False;User Id=sa;server=someserver;Password=somepassword
Thanks for your help! Please let me know if the question is still unclear.
Your configuration section will be associated with some .NET class to handle it:
<configSections>
<sectionGroup name="someDataAccessLayer">
<section name="databaseConnectionStrings" type="sometype" />
</sectionGroup>
</configSections>
So to read the settings from the <localeSettings> section, you need to use the ConfigurationManager (add a reference to System.Configuration to your project) to get those settings into an instance of that class:
sometype cs = ConfigurationManager.GetSection("someDataAccessLayer/databaseConnectionStrings") as sometype;
Now you have an object of type sometype that contains all the settings in that config section. One of those properties will be a list of database connection strings, which you can now enumerate and find the appropriate one and read it's .Value property.
App.Config Settings:
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="MyApp.LocalConnectionString"
connectionString="Data Source= .\SQLEXPRESS;Initial Catalog=DBName;Integrated Security = true"
providerName="System.Data.SqlClient" />
Access at DataLayer using the ConfigurationManager as:
// add reference
using System.Configuration;
// then access connection string in your class
private static string strConnectionString = ConfigurationManager.ConnectionStrings["MyApp.LocalConnectionString"].ConnectionString;

Resources