Quantcast
Viewing latest article 3
Browse Latest Browse All 5

Commented Issue: How to use LocalDB Wrapper without windows authentication? [1]

How to use the the class to create a database that __doesn't use integrated security__?

I am successfully using the wrapper to create an instance and attach or create a database
but when I move the database file, __I can't open that on another computer__?
How do you go about fixing that?

I saw this explained in Microsoft KB - http://msdn.microsoft.com/en-au/library/hh212961.aspx
````
CREATE LOGIN NewLogin WITH PASSWORD = 'Passw0rd!!@52';
GO
CREATE USER NewLogin;
GO
EXIT
````
Execute the following code to connect to the shared instance of LocalDB using the NewLogin login.
````
sqlcmd –S (localdb)\.\DeptSharedLocalDB -U NewLogin -P Passw0rd!!@52
````

Any help much appreciated!

What I am currently doing is working great... -> i.e
```
instanceName = Guid.NewGuid().ToString();
instance = provider.CreateInstance(instanceName);
instance.Start();

connection = instance.CreateConnection();
connection.Open();

string commandText = string.Format("CREATE DATABASE {0} ON (name = '{1}_data', filename = '{2}')", name, name, path);
using (SqlCommand command = new SqlCommand(commandText, connection))
{
command.ExecuteNonQuery();
}
```
or
```
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = string.Format("CREATE DATABASE {0} ON (FILENAME = '{1}') FOR ATTACH", name, path);
command.ExecuteNonQuery();
}
```


Comments: Hi there, I apologise for the tardiness in the response. The email notification for issues from CodePlex to me appears to have been lost. I only noticed this while migrating the repository to GitHub. I'll take a look into this and see if there's a way to do this, I've never tried to port an SQL LocalDB database across machines. My guess would be that it's related to the way that SQL LocalDB runs in the context of the current logged-in Windows Principal, but I'll at least look at creating an SQL login instead of using Windows Authentication.

Viewing latest article 3
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>