CGI and SQLConnection
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: CGI and SQLConnection

  1. #1
    Join Date
    Oct 2010
    Posts
    5

    CGI and SQLConnection

    Hi,
    I am rewrite code from VC2010 (unmanaged Console Application CGI-Common Gateway Interface) to C++/CLI, where section „SQL Connect“ its problem for internet user IUSR_PCNAME.

    int main(array<System::String ^> ^args)
    {
    printf("Content-type: text/html\n\n") ;
    printf("<html>\n");
    printf("<head>\n");
    printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1250\">\n");
    printf("<title>aaa</title></head>\n") ;
    printf("<body>\n") ;
    // Connect to SQL
    ///////////////////////
    String ^query = "SELECT * FROM tsble_name";
    String ^ connectString = "Data Source=MARIANPC;Database=db_name;“ +
    "Integrated Security=True;UID=sa;Password=xxxxxx;";
    SqlConnection^ sqlconn = gcnew SqlConnection(connectString); // running error
    // running error for user IUSR_MARIANPC http://MARIANPC/cgi-bin/aa.exe
    // running from command line (windows user): cd c:\inetpub\wwwroot\cgi-bin
    // aa.exe – no problem)
    sqlconn->Open();
    SqlCommand ^sqlCommand = gcnew SqlCommand(query, sqlconn);
    SqlDataReader ^dataReader = sqlCommand->ExecuteReader();
    int numCols = dataReader->FieldCount;
    Console::Write("No. of columns:");
    Console::WriteLine(numCols);
    while(dataReader->Read())
    {
    for (int c = 0; c < numCols-1; c++)
    {
    Console::Write(dataReader[c]);
    Console::Write("\t");
    }
    Console::WriteLine("");
    }
    //////////////////////////////////////////////////
    printf("</body>\n");
    printf("</html>\n");
    return 0;
    }

    Error Log:
    Neošetřená výjimka: System.TypeInitializationException: Inicializační metoda typu System.Data.SqlClient.SqlConnection vyvolala výjimku. ---> System.TypeInitializationException: Inicializační metoda typu System.Data.SqlClient.SqlConnectionFactory vyvolala výjimku. ---> System.TypeInitializationException: Inicializační metoda typu System.Data.SqlClient.SqlPerformanceCounters vyvolala výjimku. ---> System.Configuration.ConfigurationErrorsException: Nepodařilo se inicializovat konfigurační systém. ---> System.ArgumentException: Cesta obsahuje neplatné znaky. v System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str) v System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) v System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) v System.AppDomainSetup.VerifyDir(String dir, Boolean normalize) v System.AppDomainSetup.get_ConfigurationFile() v System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig) v System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig) v System.Configuration.ClientConfigurationHost.get_ConfigPaths() v System.Configuration.ClientConfigurationHost.GetStreamName(String configPath) v System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp() v System.Configuration.ClientConfigurationSystem..ctor() v System.Configuration.ConfigurationManager.EnsureConfigurationSystem() --- Konec trasování zásobníku pro vnitřní výjimku --- v System.Configuration.ConfigurationManager.EnsureConfigurationSystem() v System.Configuration.ConfigurationManager.PrepareConfigSystem() v System.Configuration.ConfigurationManager.GetSection(String sectionName) v System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName) v System.Diagnostics.DiagnosticsConfiguration.GetConfigSection() v System.Diagnostics.DiagnosticsConfiguration.Initialize() v System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings() v System.Diagnostics.Switch.InitializeConfigSettings() v System.Diagnostics.Switch.InitializeWithStatus() v System.Diagnostics.Switch.get_SwitchSetting() v System.Diagnostics.TraceSwitch.get_Level() v System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp) v System.Data.SqlClient.SqlPerformanceCounters..ctor() v System.Data.SqlClient.SqlPerformanceCounters..cctor() --- Konec trasování zásobníku pro vnitřní výjimku --- v System.Data.SqlClient.SqlConnectionFactory..cctor() --- Konec trasování zásobníku pro vnitřní výjimku --- v System.Data.SqlClient.SqlConnection..cctor() --- Konec trasování zásobníku pro vnitřní výjimku --- v System.Data.SqlClient.SqlConnection..ctor() v System.Data.SqlClient.SqlConnection..ctor(String connectionString) v getpost.getdata() v main(String[] args) v mainCRTStartupStrArray(String[] arguments) Content-type: text/html

    Thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center