[英]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.