简体   繁体   English

在 IIS 服务器上托管网站时无法创建数据库。 在本地它正在工作

[英]Unable to create database when hosting website on IIS Server. Locally it's working

I'm unable to create a database when hosting a website on IIS Server.在 IIS 服务器上托管网站时,我无法创建数据库。 Locally it's working.在本地它正在工作。 I just want to execute this procedure via a URL.我只想通过 URL 执行此过程。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE dbo.createdb
(
    @cmd varchar(1000),
    @dbname varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = @dbname)
    BEGIN
    SET @cmd=' CREATE database '+ @dbname;
    EXEC (@cmd);
    END
END
 public void createDB(string _date)
{
    myConnectionString = string.Empty;
    string dbName = _date;
    myConnectionString = "Data Source=localhost; initial catalog=xxxxxxxx;Persist Security Info=True; user id=xxxxxx; password=xxxxxxx; Connection Timeout=7000;";
    using (SqlConnection conn = new SqlConnection(myConnectionString.ToString()))
    {
        DataSet ds = new DataSet();
        conn.Open();           
        string sql = string.Empty;
        try
        {
            SqlCommand Cmd = new SqlCommand("createdb", conn);
            Cmd.CommandType = CommandType.StoredProcedure;
            Cmd.Parameters.AddWithValue("@dbname", dbName);
            Cmd.ExecuteNonQuery();

        }
        catch (Exception e)
        {
            string data = e.Message;
            RecordErrorLog("CreateMyFile¶" + data + "¶" + myConnectionString);
        }
        finally
        {
            if (conn.State != ConnectionState.Closed)
                conn.Close();
        }
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在远程 IIS 服务器上托管网站,无法插入 SQL Server 数据库 - Hosting website on remoter IIS server, Cannot Insert into SQL Server database 仅在 IIS 服务器上本地运行时,将用户名和密码传递给经过身份验证的代理服务器。 ASP 核心 2.0 - Pass username and password to authenticated proxy server when running locally only on IIS server. ASP core 2.0 在IIS中托管时无法获取用户位置 - Unable to get user location when hosting in IIS 托管到IIS时无法访问打印机 - Unable to access the printer when hosting to iis 部署到 IIS 服务器后未显示 RDLC 报告。 它在我开发应用程序的同一系统上工作 - RDLC reports are not showing after deployed to IIS server. It's working on same system where I am developing the application 在IIS网站中托管更多Web API时,Owin未经授权 - Owin Unauthorised when hosting more web apis inside IIS website IIS 上的应用程序托管不起作用 - Application hosting on IIS is not working 网站在 IIS 中运行时找不到 DLL - Unable to find DLL when website runs in IIS 将网站托管在IIS中时,无法使用ADO.NET实体数据模型连接数据库 - Unable to connect database using ADO.NET entity data model when website is hosted in IIS 托管后,Google Calendar API无法在IIS服务器中运行 - Google Calendar API not working in IIS server after hosting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM