首页 程序员大本营 98sky.com 程序员问答大本营 98sky.com.
Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


5 questions online user: 11

0
votes
answers
31 views
+10

數據庫的初始化2

0

我已創建了asp.net mvc的核心2.數據庫的初始化2

此應用程序與數據庫和實體框架的核心一個非常基本的Web應用程序。我曾與Migration和Code First戰略合作過。

一切工作正常。

我也可以用命令創建數據庫:

$ dotnet ef database update 

什麼,我想在這個時候要做的是在數據庫中創建一些數據(從C#代碼)。

我看了一些教程和我創建了包含代碼,將創建我的數據DataInitializer類。

我已經把這個線在Startup.cs配置方法的末尾:

DataInitializer dataseed = new DataInitializer(); 
    dataseed.InitializeDataAsync(app.ApplicationServices); 

的問題是數據插在每個我跑我的應用程序的時間。

我不想用C#代碼,如果數據是即使在數據庫,因爲它是非常危險的檢查。

我想要做什麼是觸發數據初始化與遷移。可能嗎 ?

感謝

0
votes
answers
18 views
+10

PowerShell輸出在手動和程序化執行之間有所不同

1

當手動運行vs編程時,我得到了來自同一命令的兩個不同輸出,我不明白爲什麼。PowerShell輸出在手動和程序化執行之間有所不同

問題::命令powershell -Command "Get-Module -ListAvailable"

當在命令提示符下手動運行,我得到這個輸出::

U:>powershell -Command "Get-Module -ListAvailable" 

Directory: C:Program FilesWindowsPowerShellModules 

ModuleType Version Name        ExportedCommands 
---------- ------- ----        ---------------- 
Binary  1.0.0.1 PackageManagement     {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} 
Script  1.0.0.1 PowerShellGet      {Install-Module, Find-Module, Save-Module, Update-Module...} 
Binary  6.5.1.6... VMware.DeployAutomation    {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...} 
Binary  6.5.1.6... VMware.ImageBuilder     {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, Export-EsxImageProfile...} 
Manifest 6.5.4.7... VMware.PowerCLI 
Binary  6.5.4.6... VMware.VimAutomation.Cis.Core  {Connect-CisServer, Disconnect-CisServer, Get-CisService} 
Binary  6.5.1.5... VMware.VimAutomation.Cloud   {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...} 
Manifest 6.5.4.6... VMware.VimAutomation.Common 
Binary  6.5.2.6... VMware.VimAutomation.Core   {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...} 
Binary  6.5.4.7... VMware.VimAutomation.HA    Get-DrmInfo 
Binary  7.1.0.5... VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer} 
Binary  6.5.1.5... VMware.VimAutomation.License  Get-LicenseDataManager 
Binary  2.0.0.6... VMware.VimAutomation.Nsxt   {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtService} 
Binary  6.5.1.5... VMware.VimAutomation.PCloud   {Connect-PIServer, Disconnect-PIServer, Get-PIComputeInstance, Get-PIDatacenter} 
Manifest 1.0.0.5... VMware.VimAutomation.Sdk   {Get-PSVersion, Get-InstallPath} 
Binary  6.5.1.5... VMware.VimAutomation.Srm   {Connect-SrmServer, Disconnect-SrmServer} 
Binary  6.5.4.7... VMware.VimAutomation.Storage  {Add-KeyManagementServer, Copy-VDisk, Export-SpbmStoragePolicy, Get-KeyManagementServer...} 
Script  1.1  VMware.VimAutomation.StorageUtility Update-VmfsDatastore 
Binary  6.5.1.5... VMware.VimAutomation.Vds   {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwitch...} 
Binary  6.5.4.7... VMware.VimAutomation.Vmc   {Connect-Vmc, Disconnect-Vmc, Get-VmcService, Connect-VmcServer...} 
Binary  6.5.1.5... VMware.VimAutomation.vROps   {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...} 
Binary  6.5.1.5... VMware.VumAutomation    {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...} 

Directory: C:Windowssystem32WindowsPowerShellv1.0Modules 

ModuleType Version Name        ExportedCommands 
---------- ------- ----        ---------------- 
Manifest 1.0.0.0 AppLocker       {Set-AppLockerPolicy, Get-AppLockerPolicy, Test-AppLockerPolicy, Get-AppLockerFileInformation...} 
Manifest 1.0.0.0 BitsTransfer      {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTransfer...} 
Manifest 1.0.0.0 CimCmdlets       {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSession...} 
Script  1.0.0.0 ISE         {New-IseSnippet, Import-IseSnippet, Get-IseSnippet} 
Manifest 1.0.0.0 Microsoft.PowerShell.Archive  {Compress-Archive, Expand-Archive} 
Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...} 
Manifest 3.0.0.0 Microsoft.PowerShell.Host   {Start-Transcript, Stop-Transcript} 
Manifest 3.1.0.0 Microsoft.PowerShell.Management  {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...} 
Script  1.0  Microsoft.PowerShell.ODataUtils  Export-ODataEndpointProxy 
Manifest 3.0.0.0 Microsoft.PowerShell.Security  {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...} 
Manifest 3.1.0.0 Microsoft.PowerShell.Utility  {Format-List, Format-Custom, Format-Table, Format-Wide...} 
Manifest 3.0.0.0 Microsoft.WSMan.Management   {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSSP, Set-WSManQuickConfig...} 
Manifest 1.0.0.0 NetworkSwitchManager    {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEthernetPort, Get-NetworkSwitchEthernetPort, Remove-NetworkSwitchEthernetPortIPAddress...} 
Manifest 1.1  PSDesiredStateConfiguration   {Set-DscLocalConfigurationManager, Start-DscConfiguration, Test-DscConfiguration, Publish-DscConfiguration...} 
Script  1.0.0.0 PSDiagnostics      {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSManTrace, Enable-PSTrace...} 
Binary  1.1.0.0 PSScheduledJob      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-JobTrigger...} 
Manifest 2.0.0.0 PSWorkflow       {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn} 
Manifest 1.0.0.0 PSWorkflowUtility     Invoke-AsWorkflow 
Manifest 1.0.0.0 TroubleshootingPack     {Get-TroubleshootingPack, Invoke-TroubleshootingPack} 

Directory: C:opscodechefdkmodules 

ModuleType Version Name        ExportedCommands 
---------- ------- ----        ---------------- 
Script  0.0  chef        {chef-apply, chef-client, chef-service-manager, chef-shell...} 

當編程方式運行(通過Java),我得到這樣的輸出::

ModuleType Name      ExportedCommands               
---------- ----      ----------------               
Binary  PackageManagement   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}  
Script  PowerShellGet    {Install-Module, Find-Module, Save-Module, Update-Module...} 
Manifest BitsTransfer    {Add-BitsFile, Remove-BitsTransfer, Complete-BitsTransfer, Get-BitsTrans... 
Manifest CimCmdlets    {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSessio... 
Script  ISE      {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}       
Manifest Microsoft.PowerShell.A... {Compress-Archive, Expand-Archive}           
Manifest Microsoft.PowerShell.D... {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...}    
Manifest Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript}           
Manifest Microsoft.PowerShell.M... {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}    
Script  Microsoft.PowerShell.O... Export-ODataEndpointProxy             
Manifest Microsoft.PowerShell.S... {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}     
Manifest Microsoft.PowerShell.U... {Format-List, Format-Custom, Format-Table, Format-Wide...}     
Manifest Microsoft.WSMan.Manage... {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSSP, Set-WSManQ... 
Manifest PSDesiredStateConfigur... {Set-DscLocalConfigurationManager, Start-DscConfiguration, Test-DscConfi... 
Manifest PSDiagnostics    {Start-Trace, Stop-Trace, Enable-WSManTrace, Disable-WSManTrace...}   
Binary  PSScheduledJob   {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-JobTrigger...}  
Manifest TroubleshootingPack  {Get-TroubleshootingPack, Invoke-TroubleshootingPack}      
Script  chef      {chef-apply, chef-client, chef-service-manager, chef-shell...}    

編程運行i的輸出s缺少「版本」列,並且只是可用模塊的一個子集。

我想也許不知何故,我調用了兩個不同的PowerShell可執行文件,所以我手動和編程運行powershell -Command "$PSVersionTable"

powershell -Command "$PSVersionTable"手動運行::

Name       Value 
----       ----- 
PSVersion      5.0.10586.117 
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0...} 
BuildVersion     10.0.10586.117 
CLRVersion      4.0.30319.18444 
WSManStackVersion    3.0 
PSRemotingProtocolVersion  2.3 
SerializationVersion   1.1.0.1 

powershell -Command "$PSVersionTable"的綱領性運行::

Name       Value                                         
----       -----                                         
PSVersion      5.0.10586.117                                       
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0...}                                     
BuildVersion     10.0.10586.117                                       
CLRVersion      4.0.30319.18444                                       
WSManStackVersion    3.0                                          
PSRemotingProtocolVersion  2.3                                          
SerializationVersion   1.1.0.1 

所以我覺得我運行的輸出輸出相同的PowerShell可執行文件。

任何人有什麼想法,爲什麼我運行相同的命令時,我得到2完全不同的輸出?

UPDATE :: 在@EBGreen的要求下,我包含了用於以編程方式運行命令的實際Java代碼。

public class Example { 

    private void myMethod(String command) throws IOException { 
     Process process = Runtime.getRuntime().exec(command); 
     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); 

     String output = ""; 
     String line; 
     while((line = bufferedReader.readLine()) != null){ 
      output += (line + "
"); 
     } 

     System.out.println((output.isEmpty() ? "No output was received!!!" : output)); 


     BufferedReader errorBufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); 
     String errorOutput = ""; 
     while((line = errorBufferedReader.readLine()) != null){ 
      errorOutput += (line + "
"); 
     } 

     System.out.println((errorOutput.isEmpty() ? "Nothing in the error output stream." : errorOutput)); 
    } 


    public static void main(String[] args) throws IOException { 
     new Example().myMethod("powershell -Command "Get-Module -ListAvailable""); 
    } 

} 
+0

您以編程方式運行時使用的實際代碼是什麼。命令是否在相同的用戶環境中運行?是一個64位和另一個32位? – EBGreen

+0

@EBGreen我會在一秒內發佈一個包含代碼的問題更新。 – Chiefwarpaint

+0

@EBGreen代碼現已包含在帖子中。程序化執行是通過IntelliJ中的32位JDK完成的。手動執行通過cmd提示符('C: Windows system32 cmd.exe')完成。主機操作系統是64位Win 7. – Chiefwarpaint

0
votes
answers
32 views
+10

Android數據綁定無法解析符號(gradle 3.0.1)

1

我想我可能會丟失一些明顯的東西,綁定無法訪問我的textview ID?例如。Android數據綁定無法解析符號(gradle 3.0.1)

binding.myText.setText(「text here」); >無法解析符號 '會將myText'


MainActivity.java

public class MainActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); 
     binding.myText.setText("test"); 
    } 
} 


activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/myText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent"/> 
    </android.support.constraint.ConstraintLayout> 
</layout> 

編輯


應用程序/的build.gradle 應用插件: 'com.android.application'

android { 
    compileSdkVersion 26 
    defaultConfig { 
     applicationId "com.example.francoismarais.myapplication" 
     minSdkVersion 15 
     targetSdkVersion 26 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    dataBinding { 
     enabled = true 
    } 
} 

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 

    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
} 

的build.gradle(根)

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 

    repositories { 
     google() 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:3.0.1' 


     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     google() 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 
+1

你嘗試過乾淨/重建嗎? – MHogge

+0

我做了,讓我試試無效緩存並重新啓動。我還添加了我的gradle文件,maby缺少那裏:| – Francois

+1

好吧,我做了一個無效的緩存並重新啓動,似乎已經將其踢入現在的工作狀態:)對於顯而易見的問題抱歉 – Francois

0
votes
answers
22 views
+10

用sqlsrv插入查詢

0

當我嘗試在我的數據庫中插入一個值時,它返回我沒有錯誤,但它沒有插入任何東西,在sql server上它完美地工作。用sqlsrv插入查詢

<?php 
$serverName = "12.15.88.81"; 
$connectionInfo = array("Database"=>"Dcs", "UID"=>"sa", "PWD"=>"123456"); 
$conn = sqlsrv_connect($serverName, $connectionInfo); 
if($conn === false) { 
    die(print_r(sqlsrv_errors(), true)); 

} 
if (sqlsrv_begin_transaction($conn) === false) { 
    die(print_r(sqlsrv_errors(), true)); 
} 
$sql = "INSERT INTO [dbo].[Dcs_name] (ID,NAME) VALUES (?,?)"; 
$params = array('11','Ani'); 
$stmt = sqlsrv_query($conn, $sql, $params); 



$stmt = sqlsrv_query($conn, $sql, $params); 

if($stmt === false) { 
    if(($errors = sqlsrv_errors()) != null) { 
     foreach($errors as $error) { 
      echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />"; 
      echo "code: ".$error[ 'code']."<br />"; 
      echo "message: ".$error[ 'message']."<br />"; 
     } 
    } 
} 

?> 
+0

我沒有使用sql-server函數,但它看起來像你正在開始一個事務,你需要提交這個更改來應用。 http://php.net/manual/en/function.sqlsrv-commit.php另外,不要執行查詢兩次,我會有'id'自動增量。 – chris85

+0

檢查此:最佳方式找出 - https://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row?rq=1 – vbRocks

0
votes
answers
25 views
+10

巴貝爾38年8月5日無視Node.js的

0

等待我有問題,巴貝爾38年5月8日,等待中的Node.js 我的代碼看起來像:巴貝爾38年8月5日無視Node.js的

/** 
* Imports 
*/ 
import {signature} from '../core/antpool'; 
import log from '../core/logging'; 
import config from '../config'; 
import {sendLog as sendEmailLog, EmailTemplate} from '../core/email'; 
import {rethinkdb, Decorators as DBDecorators} from '../core/db'; 
import request from 'request'; 

const tables = { 
    AntpoolAccount: 'CronAntpoolAccount' 
}; 

class Antpool { 

    @DBDecorators.table(tables.AntpoolAccount) 
    static async account(coin) { 
     var nonce = Date.now(); 
     request.post({ 
      url: config.antpool.baseUrl + '/api/account.htm', 
      json: true, 
      form: { 
       key: config.antpool.key, 
       nonce: nonce, 
       signature: signature(nonce), 
       coin: coin 
      } 
     }, function (err, httpResponse, body) { 
      if (err || httpResponse.statusCode != 201) { 
       log.error(err, '[CRON][Antpool][Account] Connection problem'); 
       sendEmailLog(EmailTemplate.LOG, { 
        message: '[CRON][Antpool][Account] Connection problem' 
       }); 
       return false; 
      } 

      var out = JSON.parse(body); 
      if (out.code != 0) { 
       log.error(err, '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message); 
       sendEmailLog(EmailTemplate.LOG, { 
        message: '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message 
       }); 
       return false; 
      } 

      // Add to database 
      let obj = { 
       earn24: out.data.earn24Hours, 
       earnTot: out.data.earnTotal, 
       paidOut: out.data.paidOut, 
       balance: out.data.balance, 
       createdAt: new Date() 
      }; 

      // Insert into database 
      let insert = await this.table.insert(obj).run(); 

      if(insert) { 
       return true; 
      } else { 
       return false; 
      } 

     }); 
    } 

} 

/** 
* Exports 
*/ 
export {Antpool}; 

我所得到的只是錯誤,有問題等待。

SyntaxError: .../antpool.js: Unexpected token (59:22) 

      // Insert into database 
      let insert = await this.table.insert(obj).run(); 

我在想什麼可以解決方案接受等待。這是不是很奇怪,因爲在代碼的其他部分等待運作良好。 不確定究竟是什麼問題,但花了大約兩天才發現問題。

我打電話的腳本有:

/** 
* Automatically hook babel into all node requires. 
*/ 
require('babel/register')({ 
    optional: ['es7.asyncFunctions', 'es7.classProperties', 'es7.decorators'] 
}); 

/** 
* Start application worker. 
*/ 
require('./src/worker'); 

任何幫助是非常讚賞。

+2

您正在使用的函數中等待「功能(ERR,HttpResponse對象,型)」未署名爲異步 –