2017-08-31 124 views
0

我正在开发一个Azure网站和一个WebJob。开发数据库是一个Mdf文件。 Mvc应用程序可以连接到Azure存储和数据库。该WebJob可以连接到Azure存储,但数据库抛出这样的:Azure WebJobs无法连接到mdf数据库

System.Data.SqlClient.SqlException occurred 
    HResult=0x80131904 
    Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid. 
) 
    Source=Core .Net SqlClient Data Provider 
    StackTrace: 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 
    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 

无论是MVC和WebJob共享相同的连接字符串:

Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\Projects\\Test1\\Code\\Database\\Test1.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False 

它没有如果了MVC任何区别当WebJob启动时,应用程序正在运行。

回答

0

在MVC应用程序用户的秘密,我不得不使用双斜线,这样的:

Data Source=(LocalDB)\\MSSQLLocalDB 

在为webjob控制台应用程序app.config文件,我不得不使用单斜杠是这样的:

Data Source=(LocalDB)\MSSQLLocalDB